【发布时间】:2009-10-13 23:26:12
【问题描述】:
我正在尝试创建一个方法,该方法采用第一个值为集合的 Map 和第二个值为 Lists 的空 Map,并使用与第一个相同的键/值映射填充第二个 Map。第二个映射将具有第一个映射中的每个键,但与之关联的是一个列表,该列表包含它映射到的 Set 中的所有相同元素。在第二个地图中使用 ArrayList。这是我得到的方法。
public static<K,E> void values(Map<K, Set<E>> ml, Map<K, List<E>> m2){
for (Map.Entry<K, Set<E>> e; e < ml.size(); ? // I am not sure what to write here: a e.hasNext() or a e.next)
// then i have to use a put method right?
m2.put(e.getKey(), new ArrayList<E>(? )) // I don't know how to get the value, would it just be the same as e.getKey() or e.value
}
你能告诉我你会怎么做吗?或者如果有什么问题? 谢谢你的帮助
【问题讨论】: