How to print a list in Java?

To print a list in Java, just pass it to the System.out.println method.

System.out.println will call toString on the list, and you will get a reasonable, comma-separated output:

List<String> list = new ArrayList<>();

list.add("one");
list.add("two");
list.add("three");

System.out.println(list); // [one, two, three]