问题描述
- 关于concrrentHashMap的替换覆盖问题
-
//路由表
ConcurrentHashMap> RouteTable=new ConcurrentHashMap>();
//当前路由路径
ConcurrentHashMap RouteSet=new ConcurrentHashMap();Iterator> it = distanceMap.entrySet().iterator();
int min = Integer.MAX_VALUE;
node = -1;
while (it.hasNext()) {
Entry entry = it.next();
if (entry.getValue() < min) {
node = entry.getKey();
System.out.println(node);
RouteSet.put(startIndex,node);
RouteTable.put(node,RouteSet);
System.out.println("初始路由表:"+RouteTable);
}}这是输出结果,本意是初始化路由表,对RouteTable的每个不同KEY值进行赋给VALUE,但是现在只要更新VALUE,就会覆盖所有的键值对,更新到最后一次的键值,这怎么回事啊?求解救
时间: 2024-08-30 04:19:16