java 如何遍历concurrenthashmap

2025-04-22 04:28:50
推荐回答(2个)
回答1:

和遍历HashMap是一样的,有多种方法,给出计算较少的一种

ConcurrentHashMap map=....数据
for(Map.Entry e: map.entrySet() ){
        System.out.println("键:"+e.getKey()+", 值:"+e.getValue());
}

回答2:

你到jdk的demo里面搜索map,就会看到啦,你还可以到编辑器eclipse什么的上面先new个map,然后再到下面for,提示下就可以了