如何从Map<K,Collection<V>>创建多地图<K,V>?
我没有找到这样的多地图结构...当我想要这样做时,我会遍历地图,并填充多地图。还有别的方法吗?
final Map<String, Collection<String>> map = ImmutableMap.<String, Collection<String>>of(
"1", Arrays.asList("a", "b", "c", "c"));
System.out.println(Multimaps.forMap(map));
final Multimap<String, String> expected = ArrayListMultimap.create();
for (Map.Entry<String, Collection<String>> entry : map.entrySet()) {
expected.putAll(entry.getKey(), entry.getValue());
}
System.out.println(expected);
第一个结果是,但我期望{1=[[a, b, c, c]]}
{1=[a, b, c, c]}