Multiple methods of 24.HashMap

Source: Internet
Author: User

 PackageCn.jbit.map;ImportJava.util.HashMap;ImportJava.util.Map;/*** Test multiple methods of HashMap. */ Public classTestMap { Public Static voidMain (string[] args) {//1. Use HashMap to store key-value pairs for multiple sets of national abbreviations and Chinese namesMap countries =NewHashMap (); Countries.put ("CN", "People's Republic of China"); Countries.put ("RU", "Russian Federation"); Countries.put ("FR", "French Republic"); Countries.put ("US", "United States of America"); //2. Display the Chinese full name of the corresponding country "CN"String country = (string) countries.get ("CN"); System.out.println ("CN corresponds to the country:" +country); //3. Display the number of elements in the collectionSYSTEM.OUT.PRINTLN ("Map has" +countries.size () + "group data"); /*4. Two times to determine if the "FR" key exists in the map*/System.out.println ("Does the map contain a FR key?" +Countries.containskey ("FR")); Countries.remove ("FR"); System.out.println ("Does the map contain a FR key?" +Countries.containskey ("FR")); /*5. Display key set, value set and key value pair set respectively*/System.out.println (Countries.keyset ());        System.out.println (Countries.values ());        SYSTEM.OUT.PRINTLN (countries); /*3. Empty the HashMap and Judge*/countries.clear (); if(Countries.isempty ()) System.out.println ("The data in the map has been emptied!" "); }}

Multiple methods of 24.HashMap

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.