如何将地图内容添加到Multimap?

时间:2013-07-01 09:56:06

标签: java guava

Map<String,String> map1= new HashMap<String, String>(){{
            put("no1","123"); put("no2","5434"); put("no5","234");}};        

Map<String,String> map2 = new HashMap<String, String>(){{
            put("no1","523"); put("no2","234"); put("no3","234");}};


Multimap<String, String> totalMap = ArrayListMultimap.create();

totalMap.putAll()仅支持Multimap。如何将所有map1和map2放入多图?

1 个答案:

答案 0 :(得分:6)

使用Multimaps.forMap(Map<K,V>)获取地图的Multimap视图,然后将其添加到totalMap,例如:

totalMap.putAll(Multimaps.forMap(map1));