我没有找到这样的多图构造……当我想这样做时,我遍历地图,并填充多图。还有别的办法吗?
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]}
原文由 sly7_7 发布,翻译遵循 CC BY-SA 4.0 许可协议
假设你有
那么我相信这是你能做的最好的
或更优,但更难阅读