Java, Programming

How To Print an ArrayList In Java 8

how-to-print-an-arraylist-in-java-8

List of String

List<String> list = Arrays.asList("1", "2", "3");
System.out.println(String.join(", ", list));

Output:

1, 2, 3

 

List of Object

List<Object> list = Arrays.asList(new Object(), new Object(), new Object());
System.out.println(Arrays.toString(list.toArray()));

Output:

[[email protected], [email protected], [email protected]]