Java:map excuses and their subclasses HashMap five, Identityhashmap sub-class
Understanding: Identityhashmap Sub-class
In general, the standard map, there is no duplicate key is worth the value, the same key is overwritten. HashMap
Identityhashmap is an exception, he allows the key value to repeat, only if two objects with "= =" to judge, can judge him equal.
map<string, integer> map = new identityhashmap<string,integer> (); Map.put (New String ("Zhangsan"), 30); Map.put (New String ("Zhangsan"), 31); SYSTEM.OUT.PRINTLN (map);
Result: {zhangsan=30, zhangsan=31}
Iterator output:
map<string, integer> map = new identityhashmap<string,integer> (); Map.put (New String ("Zhangsan"), 30); Map.put (New String ("Zhangsan"), 31); set<string> keys = Map.keyset ();iterator<string> iter = Keys.iterator (); while (Iter.hasnext ()) {String key = Iter.next (); SYSTEM.OUT.PRINTLN (key +--+ + map.get (key));} SYSTEM.OUT.PRINTLN (map);
Results:
Zhangsan-->30zhangsan-->31{zhangsan=30, zhangsan=31}
Java:map excuses and their subclasses HashMap five, Identityhashmap sub-class