我想从哈希映射中检索k,v对。 entrys是这样的:递归迭代哈希映射
a = 3,4
b = 5,6
等等。我需要这些值的组合。
a=3, b=5.
a=3, b=6.
a=4, b=5.
a=4, b=6.
我不知道值多少个键,多少entrys有。与入口集我可以得到的价值,但不是组合。它看起来像递归,但如何?
这里是我的代码:
HashMap<String, String[]> map = new HashMap<String, String[]>();
BufferedReader file = new BufferedReader(new FileReader("test.txt"));
String str;
while ((str = file.readLine()) != null) {
... logic
map.put(key, value);
}
System.out.println("number of keys: " + map.size());
for(Entry<String, String[]> entry : map.entrySet()) {
for(String value : entry.getValue()) {
System.out.println(entry.getKey() + ": " + value);
}
}
file.close();
我不清楚:“a”是你的钥匙和“3”(从列表中)你的价值,或者是“3”你的钥匙是从a和“5”你的价值? – 2011-03-16 09:10:44
a是关键,3和4是字符串。因此“String []”。值是String [] – zyamat 2011-03-16 09:18:12