我是靠谱客的博主 烂漫小伙,最近开发中收集的这篇文章主要介绍Map的remove()方法,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

测试代码如下: 

    public static void main(String[] args) {
        Map<String, String> map = new HashMap<>();
        map.put("aa", "ssssss");
        map.put("bb", "cccccc");
        map.put("cc", "ffffff");
        map.put("dd", "gggggg");
        map.put("ee", "kkkkkk");

        String contaions = "aa";
        System.out.println("before: contains " + contaions + " : " + map.containsKey(contaions));
        System.out.println("before: map = " + JSONObject.toJSONString(map, SerializerFeature.WriteMapNullValue));
        System.out.println("----------------------------------------------------------------------------");
        System.out.println("remove: " + contaions);
        map.remove(contaions);
        System.out.println("after remove: contains " + contaions + " : " + map.containsKey(contaions));
        System.out.println("after remove: map = " + JSONObject.toJSONString(map, SerializerFeature.WriteMapNullValue));
        System.out.println("----------------------------------------------------------------------------");
        System.out.println("put null: " + contaions);
        map.put(contaions, null);
        System.out.println("after put null: contains " + contaions + " : " + map.containsKey(contaions));
        System.out.println("after put null: map = " + JSONObject.toJSONString(map, SerializerFeature.WriteMapNullValue));

    }

结果如下:

before: contains aa : true
before: map = {"aa":"ssssss","bb":"cccccc","cc":"ffffff","dd":"gggggg","ee":"kkkkkk"}
----------------------------------------------------------------------------
remove: aa
after remove: contains aa : false
after remove: map = {"bb":"cccccc","cc":"ffffff","dd":"gggggg","ee":"kkkkkk"}
----------------------------------------------------------------------------
put null: aa
after put null: contains aa : true
after put null: map = {"bb":"cccccc","cc":"ffffff","dd":"gggggg","ee":"kkkkkk","aa":null}

 

最后

以上就是烂漫小伙为你收集整理的Map的remove()方法的全部内容,希望文章能够帮你解决Map的remove()方法所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(45)

评论列表共有 0 条评论

立即
投稿
返回
顶部