June 2018
Beginner
722 pages
18h 47m
English
The flatMapToInt(), flatMapToLong(), flatMapToDouble() intermediate operations produce a numeric stream of a corresponding type:
List<Integer> list = List.of(1, 2, 3);list.stream().flatMapToInt(i -> IntStream.rangeClosed(1, i)) .forEach(System.out::print); //prints: 112123list.stream().flatMapToLong(i -> LongStream.rangeClosed(1, i)) .forEach(System.out::print); //prints: 112123list.stream().flatMapToDouble(DoubleStream::of) .forEach(d -> System.out.print(d + " ")); //prints: 1.0 2.0 3.0
As you can see, in the preceding code, we have used int values in the original stream. But it can be a stream of any type:
List<String> str = List.of("one", "two", "three");str.stream().flatMapToInt(s ...
Read now
Unlock full access