Print list items with Java streams

You have to decide. When you want to modify the list, you can’t combine the operations. You need two statements then.

myList.replaceAll(String::toUpperCase);// modifies the list
myList.forEach(System.out::println);

If you just want to map values before printing without modifying the list, you’ll have to use a Stream:

myList.stream().map(String::toUpperCase).forEachOrdered(System.out::println);

Leave a Comment