We can first convert the Arrays into IntStream and then make use of the IntStream.concat method to add two Arrays in Java.
Example:
import java.util.Arrays;
import java.util.stream.IntStream;
public class Example {
public static void main(String[] args) {
int[] numArray1 = {1, 2, 3, 4, 5};
int[] numArray2 = {6, 7, 8, 9, 10};
IntStream intStream1 = Arrays.stream(numArray1);
IntStream intStream2 = Arrays.stream(numArray2);
int[] result = IntStream.concat(intStream1, intStream2).toArray();
for (int element : result) {
System.out.print(element + " ");
}
}
}
Output:
You can download this article in various formats for your convenience. Choose from the options below:
Facing issues? Have Questions? Post them here! I am happy to answer!
More Posts related to Java,
- Java Jackson ObjectMapper Class with Examples
- How to add a Delay of a Few Seconds in Java Program
- Java SE JDBC Select Statement Example
- How to Word-Warp Console logs in IntelliJ
- Convert Java Array to ArrayList Code Example
- [Java] Error: Unmappable character for encoding UTF-8. Save could not be completed.
- Maven BUILD FAILURE: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin
- How to extract Java Jar/War/Ear files in Linux
- Java: Convert String to Binary
- Java Generics: Type parameter cannot be instantiated directly
- How to Create and Run a Command Line Application using Spring Boot
- How to Convert a Java Object into an Optional with Example
- [Hibernate] The method buildSessionFactory() from the type Configuration is deprecated
- How to Set JAVA_HOME PATH to Mac .zshrc profile file
- Formatting Double in Java [Examples]
- Java 8: Stream map with Code Examples
- Fix: SyntaxError: ( was never closed [Python]
- Java Split String by Spaces
- [fix] Java JDBC SQLSyntaxErrorException: Unknown database
- Fix: SpringFramework BeanDefinitionValidationException: Could not find an init method named
- Java Date Time API: LocalDateTime get(TemporalField field) examples
- How to create Date in yyyy-MM-dd format in Java
- Java: Create Temporary Directory and File and Delete when application terminates
- Fix RabbitMQ: AuthenticationFailureException: ACCESS_REFUSED
- Run Java Code Every Second
More Posts:
- How to Download Windows Notepad Text Editor - Windows
- Ways Compare Dates in Java Programming with Examples - Java
- How to Download Jira App for Mac - Jira
- SharePoint Open in the client application document opens in browser - Java
- [Solution] macOS Big Sur Installation: There is not enough free space, Additional Space Required - MacOS
- JavaScript: Generate Random Numbers between 1 and 3 - JavaScript
- Where does Notepad++ save temp files? - NotepadPlusPlus
- Copy Mac Screenshot in Clipboard instead of a png file - MacOS