ConcurrentHashMap不支持null

    @Override
    public void run(String... args) throws Exception {
        ConcurrentHashMap<String, String> concurrentHashMap = new ConcurrentHashMap<>();
        concurrentHashMap.put(null, "1");//npe
        concurrentHashMap.put("1", null);//npe
        concurrentHashMap.get(null);//npe
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put(null, "1");//ok
        hashMap.put("1", null);//ok
        System.out.println(hashMap.get(null));//"1"
        System.out.println(hashMap.get("1"));//null
    }

 

posted @ 2020-04-30 09:07  xuan_wu  阅读(358)  评论(0编辑  收藏  举报