Map implementation with duplicate keys

后端 未结 18 1751
暗喜
暗喜 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条回答
  •  心在旅途
    2020-11-22 15:56

    Learn from my mistakes...please don't implement this on your own. Guava multimap is the way to go.

    A common enhancement required in multimaps is to disallow duplicate keys-value pairs.

    Implementing/changing this in a your implementation can be annoying.

    In Guava its as simple as:

    HashMultimap no_dupe_key_plus_val = HashMultimap.create();
    
    ArrayListMultimap allow_dupe_key_plus_val = ArrayListMultimap.create();
    

提交回复
热议问题