I stumbled upon a task with a stream that I couldn't solve. I had to modify the code to print abcABC
instead of aAbBcC
.
I understand why it's printed this way.
// prints 'a b c' then prints 'A B C'
List<String> strings = List.of("a", "b", "c");
strings.stream()
.peek(str -> System.out.println(str))
.map(str -> str.toUpperCase())
.forEach(str -> System.out.println(str));
I appreciate any help.