Logo

Programming-Idioms

  • Java

Idiom #243 Print list

Print the contents of the list or array a on the standard output.

import static java.lang.System.out;
import static java.util.Arrays.deepToString;
out.println(deepToString(a));

'... Returns a string representation of the "deep contents" of the specified array. If the array contains other arrays as elements, the string representation contains their contents and so on. This method is designed for converting multidimensional arrays to strings.'
import java.util.List;
System.out.println(a);

a is a List<T>
import java.util.Arrays;
System.out.println(Arrays.toString(a));

a is an array of Object or of a primitive type
(print a)

New implementation...