top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Which two method you need to implement for key Object in HashMap ?

0 votes
639 views
Which two method you need to implement for key Object in HashMap ?
posted Jan 12, 2017 by Karthick.c

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

In order to use any object as Key in HashMap, it must implements equals and hashcode method in Java. Read How HashMap works in Java for detailed explanation on how equals and hashcode method is used to put and get object from HashMap.

answer Jan 23, 2017 by Dhaval Vaghela
Similar Questions
+1 vote

Example
Map data = new HashMap();
data.put("a","America");
data.put("a","Africa");
data.put("b","Bangladesh");

Need to have both "America" and "Africa" as value against key "a". Is there any mechanism to achieve this scenario.

...