Home > Software design >  Convert Stream<List<Integer>> to IntStream using flatMapToInt method. How to achieve? us
Convert Stream<List<Integer>> to IntStream using flatMapToInt method. How to achieve? us

Time:06-10

Example:

System.out.println("----flatMapToInt----"); 

Stream<List<Integer>> list = Stream.of( 
    Arrays.asList(1,2,3,4), 
    Arrays.asList(10,20,30,40)
); 
IntSteam list2 = list.flatMapToInt(...); 

or otherwise

CodePudding user response:

you can do like this: IntStream intStream = list.flatMapToInt(l -> l.stream().mapToInt(i -> i));

  • Related