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: 112123
list.stream().flatMapToLong(i -> LongStream.rangeClosed(1, i))
.forEach(System.out::print); //prints: 112123
list.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 -> IntStream.rangeClosed(1, s.length()))
.forEach(System.out::print); //prints: 12312312345