In Java 8, how can I get an int array from Stream <int []> without using forEach

How to convert Stream<int[]> to int[] without using forEach ?

 final Stream<int[]> stream = foos.stream() .map(foos -> insertQuery(contact, create)) .map(create::batch) .map(Batch::execute); //Batch::execute will return the int[] 
+6
source share
1 answer

Use flatMapToInt

 int[] result = stream.flatMapToInt(Arrays::stream).toArray(); 
+8
source

All Articles