24.HashMap的多個方法

來源:互聯網
上載者:User

標籤:

package cn.jbit.map;import java.util.HashMap;import java.util.Map;/** * 測試HashMap的多個方法。 */public class TestMap {    public static void main(String[] args) {        // 1、使用HashMap儲存多組國家英文簡稱和中文全稱的索引值對        Map countries = new HashMap();        countries.put("CN", "中華人民共和國");        countries.put("RU", "俄羅斯聯邦");        countries.put("FR", "法蘭西共和國");        countries.put("US", "美利堅合眾國");        // 2、顯示"CN"對應國家的中文全稱        String country = (String) countries.get("CN");        System.out.println("CN對應的國家是:" + country);        // 3、顯示集合中元素個數        System.out.println("Map中共有"+countries.size()+"組資料");        /*4、兩次判斷Map中是否存在"FR"鍵*/        System.out.println("Map中包含FR的key嗎?" +         countries.containsKey("FR"));        countries.remove("FR");        System.out.println("Map中包含FR的key嗎?" +         countries.containsKey("FR"));        /* 5、分別顯示鍵集、值集和索引值對集*/        System.out.println(countries.keySet());        System.out.println(countries.values());        System.out.println(countries);        /* 3、清空 HashMap並判斷*/        countries.clear();        if(countries.isEmpty())            System.out.println("已清空Map中資料!");    }}

 

24.HashMap的多個方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.