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? ==
(except for IdentityHashMap). You could test that pretty easily, BTW. You will get "A Value"
back, because Long
has overridden
equals()
( return value == obj.longValue()
), hashCode()
( return Long.hashCode(value)
).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.