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);
Answer from Holger on Stack Overflow
🌐
Baeldung
baeldung.com › home › java › java streams › modify and print list items with java streams
Modify and Print List Items With Java Streams | Baeldung
March 7, 2025 - The Stream API, introduced in Java 8, significantly changed the way we handle collections of objects. Streams provide a declarative and functional approach to processing data, offering a concise and expressive way to perform operations on collections. For example, we can take a list as the source, use the map() method to transform elements in the stream, and print the elements using forEachOrdered() in this way:
🌐
IncludeHelp
includehelp.com › java › how-to-print-elements-of-a-stream-in-java-8.aspx
How to print elements of a Stream in Java 8?
This method collects stream elements as a Collector object and then print the elements by using println() method. ... import java.util.stream.*; public class PrintStreamElementByForeachMethod { public static void main(String[] args) { // Here of() method of Stream interface is used to get the ...
🌐
Java Code Geeks
javacodegeeks.com › home › core java
Modifying and Printing List Items Using Java Streams - Java Code Geeks
April 16, 2024 - This was an article on how to list, update and print elements in Java using Stream. Download You can download the full source code of this example here: List, update and print elements in Java using Stream
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-print-elements-of-a-stream-in-java-8
How to print elements of a Stream in Java 8 - GeeksforGeeks
July 11, 2025 - Stream<T> peek(Consumer<? super T> action) Where, Stream is an interface and T is the type of stream elements. action is a non-interfering action to perform on the elements as they are consumed from the stream and the function returns the new stream. Program 1: ... // Java code to print the elements of Stream import java.util.stream.*; class GFG { public static void main(String[] args) { // Get the stream Stream<String> stream = Stream.of("Geeks", "For", "Geeks", "A", "Computer", "Portal"); // Print the stream using peek() // by providing a terminal operation count() stream.peek(s -> System.out.println(s)).count(); } }
🌐
JavaTechOnline
javatechonline.com › home › 7 ways to print elements of a collection in java
7 Ways To Print Elements Of A Collection In Java - JavaTechOnline
November 25, 2025 - We can print each element of our list countriesList using Lambda syntax as below: countriesList.forEach(item->System.out.println(item)); For example, here is the other simplified way to print in Java8 is by using Method Reference as below: countriesList.forEach(System.out::println); If your elements are in form of Stream, let’s see how can we print them.
Find elsewhere
🌐
Delft Stack
delftstack.com › home › howto › java › print list java
How to Print List in Java | Delft Stack
February 2, 2024 - We’ll create a list of Book objects and print each object using the toString() method. import java.util.ArrayList; import java.util.List; class Book { private String title; private String author; public Book(String title, String author) { ...
🌐
Baeldung
baeldung.com › home › java › java streams › collecting stream elements into a list in java
Collecting Stream Elements into a List in Java | Baeldung
December 3, 2025 - With the Java 16 release, we can now invoke toList(), a new method directly on the Stream, to get the List. Libraries, like StreamEx, also provide a convenient way to get a List directly from a Stream.
🌐
TutorialsPoint
tutorialspoint.com › how-to-iterate-list-using-streams-in-java
How to iterate List Using Streams in Java?
June 6, 2025 - import java.util.ArrayList; import ... //creating a sequential stream using the stream() method Stream<Integer> obj = list.stream(); //iterate over a list using stream obj.forEach(e -> { System.out.print(e + " "); }); } } ... This is another example of iterating a list using ...
🌐
Stackify
stackify.com › streams-guide-java-8
A Guide to Java Streams: In-Depth Tutorial With Examples
September 4, 2024 - By using these methods, you can avoid the overhead associated with boxing and unboxing objects. Transforms elements to an IntStream. List<String> numbersAsString = Arrays.asList("10000000000", "20000000000"); LongStream longStream = numbersAsString.stream() .mapToLong(Long::parseLong); longStream.forEach(System.out::println); This example converts a list of strings to an IntStream of integers.
🌐
GeeksforGeeks
geeksforgeeks.org › java › stream-in-java
Stream In Java - GeeksforGeeks
Stream API is a way to express and process collections of objects. Enable us to perform operations like filtering, mapping, reducing and sorting. Java Stream Creation is one of the most basic steps before considering the functionalities of the Java Stream.
Published   2 weeks ago
🌐
Java67
java67.com › 2016 › 03 › how-to-get-arraylist-from-stream-in-java8-example.html
How to Convert Stream to ArrayList in Java 8 - Collectors.toCollection() Example | Java67
It provides convenient utility methods like toList() to get a list of elements from Stream, toSet() to get elements inside a Set from Stream and toMap() to create a Map from the object stored in Stream.
🌐
Ars OpenForum
arstechnica.com › forums › operating systems & software › programmer's symposium
Java -> stream output into a List | Ars OpenForum
April 16, 2024 - Streams is one of those things I always think I understand until I try to use them. Then I get either errors I don't understand or results that aren't what I wanted. ... List<String> patterns = Files.find(Paths.get(root), 999, (path, file) -> file.isRegularFile() && path.getFileName().toString().matches(".*\\.rle")) .map(Path::toString) .collect(Collectors.toList()); I now have an idea of how much I don't understand about lambdas and streams.
🌐
Medium
medium.com › @anil.goyal0057 › mastering-java-streams-25-hands-on-examples-45d56ba52cf2
Mastering Java Streams: 25+ Hands-On Examples | by Anil Goyal | Medium
September 1, 2025 - If not provided, defaults to Collectors // .toList(). .collect(Collectors.groupingBy(word -> { if (word.length() < 5) return "short"; else if (word.length() <= 10) return "medium"; else return "long"; })) .forEach((key, value) -> System.out.println(key + ": " + value)); /** Output: * short: [date, fig, kiwi] * medium: [apple, banana, cherry, grapefruit] */ // Question 9: Find repeating characters in a string String input = "programming"; // input.chars() returns an IntStream of Unicode code points (integers), not char objects. // .mapToObj(c -> (char) c) converts each int code point to its corresponding Character object and now we have // a Stream<Character>. List<Character> collect2 = input.chars().mapToObj(c -> (char) c) // Groups characters by themselves (c -> c) and counts their occurrences.
🌐
Quora
quora.com › How-do-you-print-elements-of-an-ArrayList-in-Java
How to print elements of an ArrayList in Java - Quora
Streams (Java 8+) For more complex operations, filtering, mapping, joining. list.stream().forEach(System.out::println); To produce a single formatted string: String joined = list.stream().collect(Collectors.joining(", ")); System.out.printl...
🌐
Winterbe
winterbe.com › posts › 2014 › 07 › 31 › java8-stream-tutorial-examples
Java 8 Stream Tutorial - winterbe
Calling the method stream() on a list of objects returns a regular object stream. But we don’t have to create collections in order to work with streams as we see in the next code sample: Stream.of("a1", "a2", "a3") .findFirst() .ifPresent(System.out::println); // a1 · Just use Stream.of() ...
🌐
Stack Abuse
stackabuse.com › how-to-print-an-array-in-java
How to Print an Array in Java
February 24, 2023 - If you'd prefer some flexibility with the formatting, you might consider using Java 8 Streams. One option for printing an array is to convert it to a stream of objects, then print each element in the stream.