zoukankan      html  css  js  c++  java
  • Java review--hashMap

    Java代码:

    Map aMap =new HashMap<String, String>();
    aMap.put("1", "A");
    aMap.put("2", "B");
    aMap.put("3", "C");
    System.out.println(aMap.keySet());
    System.out.println(aMap.entrySet());
    System.out.println(aMap.values());
    

     效果图:

    keySet();键集合

    entrySet():键值对

    values():值集合

    	
    		Map aMap =new HashMap<String, String>();
    		aMap.put("1", "A");
    		aMap.put("2", "B");
    		aMap.put("3", "C");
    		//aMap.clear();//移除所有映射关系
    		Map bMap =new HashMap<String, String>();
    		bMap.putAll(aMap);
    		System.out.println(aMap.containsValue("d"));//false
    		System.out.println(aMap.keySet());//[1, 2, 3]
    		System.out.println(aMap.entrySet());//[1=A, 2=B, 3=C]
    		System.out.println(aMap.values());//[A, B, C]
    		aMap.remove("2");
    		System.out.println(aMap);//{1=A, 3=C}
    		System.out.println(aMap.size());//2
    		aMap.clear();
    		System.out.println(aMap.isEmpty());//true
    		System.out.println(bMap);//{1=A, 2=B, 3=C}
    
  • 相关阅读:
    Intern Day7
    Intern Day7
    Intern Day7
    Intern Day6
    Intern Day6
    Intern Day6
    Intern Day6
    Intern Day6
    萧萧远树疏林外,一半秋山带夕阳
    飞线
  • 原文地址:https://www.cnblogs.com/wangmei/p/5962295.html
Copyright © 2011-2022 走看看