Originally posted by Barry Gaunt: Actually it prints:
which is interesting because it implies that it is first converted to an array and then java.util.Arrays.toString is used to print it.
If the argument is null, then the result is "null". If the argument implements Formattable, then its formatTo method is invoked. Otherwise, the result is obtained by invoking the argument's toString() method.
So AbstracCollection's toString method is invoked.
Explaination. You are passing list and list1 both reference the same ArrayList, so you can add a String to list1, but you wouldn't be able to add a String to list. But since list is still pointing to the same ArrayList it will have the second added String in the ArrayList and print it.