【发布时间】:2014-07-01 08:24:42
【问题描述】:
我正在尝试使用代码循环地图:
Map<String, List<String>> newMap = new HashMap<String, List<String>>();
List<String> newList = new ArrayList<String>();
在地图上分配一些默认值
for ( int m = 1; m < attribteList.size(); m = m+2) {
String newName = newList.get(m);
newMap.put(newName , newList);
}
知道我需要在地图中添加值
for (another loop) {
String value1 = anyvalue;
String value2 = anyvalue;
Iterator it = pmMap.entrySet().iterator();
int cnt = 1;
while (it.hasNext()) {
Map.Entry pairs = (Map.Entry)it.next();
if(value1.equalsIgnoreCase(pairs.getKey().toString())) {
for (List<String> list : pmMap.values()) {
int a = list.indexOf(list);
if (a == cnt) {
list.add(value2);
}
}
}
cnt++;
}
问题是我的循环不起作用。我需要根据地图中的位置或值从地图中添加 value2
喜欢: 如果映射字符串 (15) 等于 value1 (15) 找到值为 15 的 Map Liststring 并将 value2 放入其中。
输出数据应该是这样的:
MAP: 15=[value2, 0, 0, 0] 16=[value2, 0, 0, 0, 0] 17=[value2, 0, ,0 ,0]
有人知道如何循环或搜索位置或正确列表吗?
【问题讨论】:
-
这里的
pmMap是什么? -
这应该是什么?
int a = list.indexOf(list);列表本身的索引? -
看来你是
puting 相同的列表到地图的每个键......这段代码到底应该做什么?list.indexOf(list)是什么?