[Java learning notes] the sub-interface of Map-difference between HashMap, map and hashmap

Source: Internet
Author: User

[Java learning notes] the sub-interface of Map-difference between HashMap, map and hashmap
Elements stored in the HashMap set must overwrite the hashCode and equals methods (similar to HashSet)

 

 

1 import java. util. hashMap; 2 import java. util. iterator; 3 4 import cn. itcast. p2.bean. student; 5 6 public class HashMapDemo {7 8 public static void main (String [] args) {9/* 10 * store the Student object and the Student's home location in the map set by key and value 11 */12 HashMap <Student, String> hm = new HashMap <Student, string> (); 13 14 hm. put (new Student ("lisi", 38), "Beijing"); 15 hm. put (new Student ("zhaoliu", 24), "Shanghai"); 16 hm. put (new Student ("xiaoqiang", 31), "Shenyang"); 17 hm. put (new Student ("wangcai", 38), "Dalian"); 18 hm. put (new Student ("zhaoliu", 24), "Tieling"); 19 20 Iterator <Student> it = hm. keySet (). iterator (); 21 while (it. hasNext () 22 {23 Student key = it. next (); 24 String value = hm. get (key); 25 System. out. println (key. getName () + ":" + key. getAge () + "--" + value); 26} 27 28} 29 30}

 

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.