欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ConcurrentHashMap不支持null

程序员文章站 2022-04-15 21:57:36
@Override public void run(String... args) throws Exception { ConcurrentHashMap concurrentHashMap = new ConcurrentHashMap<>(); concurre ......
    @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
    }