Reputation: 6180
LinkedHashMap<Long, String> myHashMap = new LinkedHashMap<>();
myHashMap.put(new Long(1), "A Value");
String aValue = myHashMap.get(new Long(1));
, will I get "A Value"
back? Or have I just queried for a different object (reference) and therefore I'll get an error?Upvotes: 1
Views: 75
Reputation: 49656
You will get "A Value"
back, because Long
has overridden
equals()
(return value == obj.longValue()
),hashCode()
(return Long.hashCode(value)
).Upvotes: 3
Reputation: 692121
==
(except for IdentityHashMap). You could test that pretty easily, BTW.Upvotes: 5