手写代码注意点 -- HashMap

1.定义

HashMap<String,String> hashMap = new HashMap<>();

<String,String>只需要写一遍

2.获取key和value

        //get a key/value set
        hashMap.keySet();
        hashMap.values();

        //judge whether contains key/value
        hashMap.containsKey("key");
        hashMap.containsValue("value");    

3.遍历

        //loop
        for(Map.Entry<String, String> item: hashMap.entrySet()) {
            item.getKey();
            item.getValue();
        }    

猜你喜欢

转载自www.cnblogs.com/frankcui/p/11530632.html