What is a faster method of checking to see if a new element already exists in a collection than using the equals() method on each element?

What is a faster method of checking to see if a new element already exists in a collection than using the equals() method on each element?



Answer: Use the hashCode() element on all members of the collection, sorting all elements with equal hashes in a single bucket. If the hash of a new element matches that of an existing bucket, the equals() method can be used on all the contents of the bucket.


Learn More :

Data Structures

Learn More Multiple Choice Question :