Similar to joining two arraylists or collections, this example we will demonstrate how to combine the contents of a primitive array and an object array while using java, guava and apache commons. As shown in the setup, we initialize two string arrays that represent the state capitals and two primitive arrays of type int of an arbitrary index. Each example will return an array that will contain the concatenated contents while using a simple junit test case to validate the length of the array.
Setup
Straight up Java
Java 8
By first converting the arrays to a stream and using java 8 stream we can concatenate two object arrays using java 8.
Join object arrays
Google Guava
Two guava utility classes, ObjectArrays handles object arrays and Ints pertain to int primitives, contain series of static methods for dealing with respective types.
Join object arrays
Join primitive arrays
Apache Commons
Apache commons contains a class ArrayUtils that contain operations on arrays, primitive arrays and primitive wrapper arrays.