手写代码注意点 -- 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();
        }    

 

posted on 2019-09-16 22:11  frank_cui  阅读(278)  评论(0编辑  收藏  举报

导航

levels of contents