richersoon
richersoon

Reputation: 4902

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[]

Upvotes: 6

Views: 701

Answers (1)

Misha
Misha

Reputation: 28183

Use flatMapToInt

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

Upvotes: 8

Related Questions