zoukankan      html  css  js  c++  java
  • Map 基础用法

    import java.util.Collection;
    import java.util.HashMap;
    import java.util.Map;
    import java.util.Set;
    
    public class Test {
    
    	public static void main(String[] args) {
    		
    		Map<String, Object> map = new HashMap<String, Object>();
    		map.put("hah", 123);
    		map.put("aa", 12314);
    		map.put("xu", "123");
    //		map.clear();
    		Object object = map.get("hah");
    		System.out.println("map.get:" + object);
    		
    		boolean containsKey = map.containsKey("hah");
    		System.out.println("map.containsKey:" + containsKey);
    		
    		int hashCode = map.hashCode();
    		System.out.println("map.hashCode:" + hashCode);
    		
    		boolean empty = map.isEmpty();
    		System.out.println("map.isEmpty:" + empty);
    		
    		Set<String> keySet = map.keySet();
    		System.out.println("map.keySet:" + keySet);
    
    		Object remove = map.remove("xu");
    		System.out.println("map.keySet:" + map.keySet());
    		
    		int size = map.size();
    		System.out.println("map.size:" + size);
    		
    		Collection<Object> values = map.values();
    		System.out.println("map.values:" + values);
    		
    		Set<String> keySet2 = map.keySet();
    		System.out.println("map.keySet2:" + keySet2);
    		
    		Map<String, Object> map1 = new HashMap<String, Object>();
    		map1.put("aa", "123");
    		map1.put("bb", 234);
    		
    		Map<String, Object> map2 = new HashMap<String, Object>();
    		map2.put("aa", "123");
    		map2.put("bb", 234);
    		boolean equals2 = map1.equals(map2);
    		System.out.println("map2.equals:" + equals2);
    	}
    }

      

    map.get:123
    map.containsKey:true
    map.hashCode:163837
    map.isEmpty:false
    map.keySet:[aa, hah, xu]
    map.keySet:[aa, hah]
    map.size:2
    map.values:[12314, 123]
    map.keySet2:[aa, hah]
    map2.equals:true
    

      

  • 相关阅读:
    FPGA 设计怎样进行面积优化(逻辑资源占用量优化)
    实现文件下载的java代码
    java推断字符串是否为乱码
    cocos2dx 制作单机麻将(二)
    CPU 风扇清理灰尘加油全过程图解
    初识 Cloudera Impala
    怎样设计接口?
    Android ViewPager使用具体解释
    php反射类 ReflectionClass
    memwatch的使用
  • 原文地址:https://www.cnblogs.com/xu-dong/p/6767829.html
Copyright © 2011-2022 走看看