Map

Map存储数据使用key-value(键-值)对的形式存储数据

public static void main(String[] args) {
        Map<String,    String> m = new HashMap<String,String>();
        m.put("1", "one");
        m.put("2", "two");
        m.put("3", "three");
        m.put("3", "four");
        
        System.out.println(m.size());
        System.out.println(m);
                
    }
}
输出结果是:
3
{3=four, 2=two, 1=one}
分析:key值是唯一的,当有相同的时候即表示将该key的值替换成新的value

boolean containsKey(Object key)查看给定的key是否在Map中存在。

boolean containsValue(Object value)查看给定的value是否存在Map中存在。

HashMap:使用散列算法实现的Map

TreeMap:使用二叉数算法实现的Map

原文地址:https://www.cnblogs.com/dieyaxianju/p/5115182.html