Which statements are true about method hashCode()
?.
hashCode()
is used by classes such as HashMap to determine inequality of objects.hashCode()
is used by classes such as HashSet to determine equality of objects.hashCode()
is used by class Collections.sort to order the elements of a collection.hashCode()
is used by classes like HashSet, TreeSet, and HashMap, which use hashing to group their elements into hash buckets.hashCode()
method includes use of a particular algorithm recommended by Java.a
Option (b) is incorrect.
Method equals()
is used to determine the equality of objects.
Option (c) is incorrect.
Class Collections defines two overloaded versions of method sort()
.
Both accept a List object, with or without a Comparator object.
Method sort()
sorts a List passed to it into ascending order, according to the natural ordering of its elements, or by using the order specified by a Comparator object.
Option (d) is incorrect.
Though HashSet and HashMap use hashCode()
for hashing, TreeSet doesn't.
Option (e) is incorrect.
Java doesn't recommend any particular algorithm for writing an efficient hashCode()
method.
But Java does recommend writing an efficient algorithm.