Java invert map

前端 未结 8 1350
南旧
南旧 2020-11-30 09:33

I need create inverse map - select unique values and for them find keys. Seems that only way is to iterate all key/value pairs, because entrySet returns set of so value not

8条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-30 10:29

    With Guava

    Multimaps.transformValues(Multimaps.index(map.entrySet(), Map.Entry::getValue),
            Map.Entry::getKey)
    

    You'll get a multimap (basically a map of lists) in return.

提交回复
热议问题