【发布时间】:2012-06-05 08:05:16
【问题描述】:
迭代“非规范化”集合映射的最佳方法是什么?
例如,我有以下地图:
Map<String, List<String>> relations;
为了遍历每个键 -> 每个值,我执行以下操作:
for (Entry<String,List<String>> e : relations.entries()) {
for (String s : e.getValue()) {
System.out.println(e.getKey() + " - " + s);
}
}
有没有一种优雅的方法可以用一些装饰器来解决它?
我希望找到类似的东西:
for(Entry e : Collections.getDenormalizeEntriesFromMapOfCollection(myMap)) {
System.out.println(e.getKey() + " - " + e.getValue());
}
这会给出相同的结果,只是在第二种情况下,每个键都有一个条目 -> 集合项。
【问题讨论】:
标签: java collections