Java:map excuses and their subclasses HashMap five, Identityhashmap sub-class

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.