How to create a Multimap from a Map>?

前端 未结 6 1274
难免孤独
难免孤独 2020-12-03 01:02

I didn\'t find such a multimap construction... When I want to do this, I iterate over the map, and populate the multimap. Is there an other way?

final Map<         


        
6条回答
  •  Happy的楠姐
    2020-12-03 01:17

    LinkedListMultimap mm = map.entrySet()
        .stream()
        .collect(
            () -> LinkedListMultimap.create(map.size()),
            (m, e) -> m.putAll(e.getKey(), e.getValue()),
            (m1, m2) -> m1.putAll(m2));
    

提交回复
热议问题