Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

How can I convert Stream<int[]> into 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[]
like image 531
richersoon Avatar asked Apr 02 '16 05:04

richersoon


1 Answers

Use flatMapToInt

int[] result = stream.flatMapToInt(Arrays::stream).toArray();
like image 128
Misha Avatar answered Sep 28 '22 07:09

Misha