In Java 8, how to get an int array from a stream without using foreach

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

Solution

Using flatmaptoint

int[] result = stream.flatMapToInt(Arrays::stream).toArray();
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>