Back to Browse

custom key object for HashMap | object HashMap key | custom object as key in hashmap | hashmap key

7.3K views
Aug 9, 2022
10:26

In this demonstration, I have created an Student class with only two fields for simplicity. I have overridden the hashcode and equals method such that it uses only student ID to verify the uniqueness of Student object. All other possible attributes of Student class can be changed on runtime. The key should honor the contract between hashCode() and equals(). Conclusion : In this video, we learned to design a class that can be used as the Key in the Map instances for storing the key-value pairs. In most situations, default hashCode() and equals() methods are good enough, but if we override one method then we should override another method as well to make sure they follow the contract between them. Custom key object for HashMap | object HashMap key | custom object as key in hashmap | hashmap key How to use user defined object as key in HashMap with an example HashMap example using user defined object as key your custom class as a hashmap key in java any class as key in hashmap Another Video : Topic : custom immutable class in java | user defined immutable class | interview question immutable class Link: https://www.youtube.com/watch?v=WqzhlCFN9_Y

Download

0 formats

No download links available.

custom key object for HashMap | object HashMap key | custom object as key in hashmap | hashmap key | NatokHD