Select true statements about method hashCode()
.
hashCode()
to store and retrieve their values.hashCode()
to store and retrieve its elements.hashCode()
is used to test for object equality and inequality for a class.hashCode()
for two objects of the same class returns the same value, the objects are considered equal.hashCode()
can be used to test for object inequality.a, e
In option (a), classes HashSet and HashMap use hashing to store and retrieve their values.
Hashing uses the hash Code value to determine the bucket in which the values should be stored.
Option (b) is incorrect.
TreeSet ignores the hash Code values.
A TreeSet stores its elements based on its key's natural ordering or the ordering defined by a Comparator.
Options (c) and (d) are incorrect, and (e) is correct.
The hash Code value is used to test for object inequality.
If two objects return different hash Code values, they can never be equal.
But if your objects return the same hash Code values, they can be unequal (if their equals()
returns false).