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 }
作者:iBrake
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.