简体   繁体   中英

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

使用flatMapToInt

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM