This page shows how to combine two arrays of Integer
objects into an array of Object
objects.
Integer[] firstArray = new Integer[] { 10 , 20 , 30 , 40 };
Integer[] secondArray = new Integer[] { 50 , 60 , 70 , 80 };
Object[] merged =
Stream
.of( firstArray , secondArray )
.flatMap( Stream :: of )
.toArray()
;
Arrays.toString( merged ): [10, 20, 30, 40, 50, 60, 70, 80]
➥ Is there a way to use Java streams to concatenate a pair of arrays of primitive int
values rather than objects?
int[] a = { 10 , 20 , 30 , 40 };
int[] b = { 50 , 60 , 70 , 80 };
int[] merged = … ?
I realize using Java streams may not be the most efficient way to go. But I am curious about the interplay of primitives and Java streams.
I am aware of IntStream
but cannot see how to use it for this purpose.