Greetings! With stream API it is easy to iterate over a collection and do whatever operation we like to do. Let's say we have a number list which we would like to print power of 2 of each. List<Integer> attempt1 = Arrays.asList(1, 2, 3, 4, 5); attempt1.stream().map(x -> x * x).forEach(System.out::println); // 1, 4, 9, 16, 25 What if we have a List of List? let's try that out. List<List<Integer>> attempt2 = Arrays.asList(Arrays.asList(1, 2, 3), Arrays.asList(2, 5)); Stream<List<Integer>> attempt2Stream = attempt2.stream(); attempt2Stream.map(x -> x * x).forEach(System.out::println); // compile error attempt2Stream.map(x -> x.stream().map(y -> y * y)).forEach(System.out::println); // java.util.stream.ReferencePipeline$3@4c873330, java.util.stream.ReferencePipeline$3@119d7047 As you can see Stream.map() doesn't give us the expected result for the type Stream<List<Integer>>. This is because map() operation ...
May all beings be happy, be well, be peaceful, and be free