1.

Why Do You Need To Use A Custom Object As A Key In Collection Classes Such As The Map Or Set?

Answer»

When are USING any CUSTOM object in Map as the key, then you need to OVERRIDE equals () or hashCode() METHOD and follow their contact. In other words, when you are STORING a custom object in store Collection such as SortedSet and SortedMap you can also use equals() method is consistent to compareTo () method, or those collections will not follow their contacts such as Set may provides duplicates.

When are using any custom object in Map as the key, then you need to override equals () or hashCode() method and follow their contact. In other words, when you are storing a custom object in store Collection such as SortedSet and SortedMap you can also use equals() method is consistent to compareTo () method, or those collections will not follow their contacts such as Set may provides duplicates.



Discussion

No Comment Found