Hi all,
in a callout "Using flatMap()" by Boyarsky, Jeanne. OCP Oracle Certified Professional
Java SE 11 Developer Complete Study Guide (p. 712). Wiley. Kindle Edition.
There is a strange example of using flatMap to create int stream... Why would you use a flat map for this example? FlatMap is used to flatten the content of the collection, and here the collection is ready to be streamed as is, right?
I tested with this code, prints the same result:
var integerList = List.of(1, 2, 3, 4, 5, 6);
IntStream flatInts = integerList.stream().flatMapToInt(x -> IntStream.of(x));
IntStream ints = integerList.stream().mapToInt(x -> x);
flatInts.forEach(System.out::println);
ints.forEach(System.out::println);
I got used that they explain some strange solutions later in the text, but there is no explanation for this...
Am I missing something?