String[] array = {\"a\",\"c\",\"b\"};
ArrayList list = new ArrayList();
list.add(\"a\");
list.add(\"b\");
list.add(\"
The short answer is because toString is defined in a few different places, with different behaviours.
The Arrays class defines toString as a static method, to be invoked like
Arrays.toString(arr_name);
But the Arrays class also inherits the non-static method toString from the Object class. So if called on an instance, it invokes Object.toString which returns a string representation of the object (eg: [Ljava.lang.Object;@4e44ac6a)
So Arrays.toString() and MyObject.toString() are calling different methods with the same name.
The ArrayList class inherits toString from the AbstractCollection class, where it is a non static method, so can be called on the object like:
MyArrayList.toString();
Because it's a string representation of a collection and not an object, the result is the values in a readable format like [one, two].