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:
Facing issues? Have Questions? Post them here! I am happy to answer!
More Posts related to Java,
- Deep Dive into Java 8 Predicate Interface
- Read and Parse XML file using Java DOM Parser [Java Tutorial]
- Java 8 Predicate Functional Interface isEqual() Method Example
- Convert Multidimensional Array toString In Java
- How to read int value using Scanner Class Java
- Spring Boot AI + LLM + Java Code Example
- Write to a File using Java Stream API
- Implementing Bubble Sort Algorithm using Java Program
- How to Fix XmlBeanDefinitionStoreException in Java SpringBoot ApplicationConfig.xml
- YAML Parser using Java Jackson Library Example
- [Fix] java: integer number too large compilation error
- Convert JSON String to Java GSON Object Example
- Read a file using Java 8 Stream
- Java Spring Boot 3 Web Hello World with Gradle in IntelliJ
- Ways Compare Dates in Java Programming with Examples
- Pretty Print JSON String in Java Console Output
- Java JDBC with Join Queries Example
- How to Check For Updates on Windows 11 (Step-by-Step)
- [Fix] java.net.MalformedURLException: unknown protocol
- How to display date and time in GMT Timezone in Java
- Error: LinkageError occurred while loading main class UnsupportedClassVersionError [Eclipse Java]
- How to convert a String to Java 8 Stream of Char?
- RabbitMQ Queue Listener Java Spring Boot Code Example
- 5+ Fibonacci number Series Java Program Examples [ 0 1 1 2 3 ..]
- Handling NullPointerException with Java Predicate
More Posts:
- Android Studio Change SDK Path - Android
- How to Open VS Code on Mac - MacOS
- How to deep copy a dictionary in Python - Python
- Fix Power BI error Access to the resource is forbidden when connecting SharePoint Online List as data source - SharePoint
- Open .bash_profile File in TextEdit using Terminal - MacOS
- Java Thread.sleep() Method Deep Dive with Examples - Java
- Save webpage as pdf in Google Chrome for Mac OS X - Mac-OS-X
- How to know the Docker Sandbox ID of a Container Network? - Docker