Map implementation with duplicate keys

后端 未结 18 1910
暗喜
暗喜 2020-11-22 15:23

I want to have a map with duplicate keys.

I know there are many map implementations (Eclipse shows me about 50), so I bet there must be one that allows this. I know

18条回答
  •  -上瘾入骨i
    2020-11-22 15:54

     1, Map> map = new HashMap<>();
    

    this verbose solution has multiple drawbacks and is prone to errors. It implies that we need to instantiate a Collection for every value, check for its presence before adding or removing a value, delete it manually when no values are left, etcetera.

    2, org.apache.commons.collections4.MultiMap interface
    3, com.google.common.collect.Multimap interface 
    

    java-map-duplicate-keys

提交回复
热议问题