The purpose of the hashCode
method is to return a hash code based on the contents of the object. Similarly, the purpose of the
toString
method is to provide a textual representation of the object’s contents.
Calling hashCode()
and toString()
directly on array instances should be avoided because the default implementations
provided by the Object
class do not provide meaningful results for arrays. hashCode()
returns the array’s "identity hash
code", and toString()
returns nearly the same value. Neither method’s output reflects the array’s contents.