Java Basic Knowledge Hardening Collection Framework note 55:map Collection HashMap collection (hashmap<integer,string>) case

Source: Internet
Author: User

1. HashMap collection (The key is an Integer, the value is a case of String )

2. code example:

1  Packagecn.itcast_02;2 3 ImportJava.util.HashMap;4 ImportJava.util.Set;5 6 /*7 * hashmap<integer,string>8 * Key: Integer9 * Value: StringTen  */ One  Public classHashMapDemo2 { A      Public Static voidMain (string[] args) { -         //To create a collection object -Hashmap<integer, string> HM =NewHashmap<integer, string>(); the  -         //creating elements and adding elements -         //integer i = new integer; -         //Integer i =; +         //String s = "Brigitte"; -         //Hm.put (i, s); +  AHm.put (27, "Brigitte"); atHm.put (30, "Wind Qing"); -Hm.put (28, "Elina"); -Hm.put (29, "Brigitte"); -  -         //the following notation is octal, but cannot appear with more than 8 of individual data -         //hm.put (003, "Hello"); in         //Hm.put (006, "Hello"); -         //hm.put (007, "Hello"); to         //hm.put (008, "Hello"); +  -         //Traverse theSet<integer> set =Hm.keyset (); *          for(Integer key:set) { $String value =Hm.get (key);Panax NotoginsengSYSTEM.OUT.PRINTLN (key + "---" +value); -         } the  +         //The following method is simply a string representation of the elements of the collection A         //System.out.println ("HM:" + HM); the     } +}

Run the results as follows:

Java Basic Knowledge Hardening Collection Framework note 55:map Collection HashMap collection (hashmap<integer,string>) case

Related Article

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.