This test method tries 2 ways of printing the content of a string array:
public final void testPrintArray() {Test output:
final String[] names = {"Linux", "Mac OS X", "Windows", "Solaris", null};
System.out.println("print names array directly: " + names);
System.out.println("print names with Arrays.toString(): " + Arrays.toString(names));
System.out.println("print names with Arrays.asList(): " + Arrays.asList(names));
}
print names array directly: [Ljava.lang.String;@5122cdb6Between the 2 methods, I find toString() is more natural. Arrays.toString() was introduced in Java 5, somewhat later than Arrays.asList().
print names with Arrays.toString(): [Linux, Mac OS X, Windows, Solaris, null]
print names with Arrays.asList(): [Linux, Mac OS X, Windows, Solaris, null]
Also note that a List can take null as element value, and its string representation is "null".