Combine Two Arrays of Different Types in Java

In this post, we will discuss how to combine two arrays of different types into single a new Object array in Java. The new array should contain all of the element of first array followed by all of the elements second array.

 

1. Java 8 Stream API

 

1.1. Using Stream.of()

 

1.2. Using Stream.concat()

 

1.3. Using List + Stream

 

2. System.arraycopy()

 

3. Java Collections Framework

Above code is short for the following:

 

4. External Libraries

 

4.1. Guava

 

4.2. Apache Commons Lang

 
Thanks for reading.




Please use ideone or C++ Shell or any other online compiler link to post code in comments.
Like us? Please spread the word and help us grow. Happy coding 🙂
 





Leave a Reply

Notify of
avatar
wpDiscuz