使用重复键映射实现 [英] Map implementation with duplicate keys
问题描述
你正在寻找一个多重映射,番石榴有几个实现。 Multimaps允许通过维护每个键的值的集合来保存多个键,即您可以将单个对象放入地图,但是您可以检索一个集合。
如果可以使用Java 5,我宁愿Guava的 Multimap
,因为它是泛型感知的。
I want to have 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 its easy to write your own Map that does this, but i would rather use some existing solution. Maybe something in commons-collections or google-collections?
You are searching for a multimap, and indeed both commons-collections and Guava have several implementations for that. Multimaps allow for multiple keys by maintaining a collection of values per key, i.e. you can put a single object into the map, but you retrieve a collection.
If you can use Java 5, I would prefer Guava's Multimap
as it is generics-aware.
这篇关于使用重复键映射实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!