HashMap和HashMultimap有什么区别 [英] What is difference between HashMap and HashMultimap
问题描述
我看到很多关于multimap的例子但不明白为什么Google Gauva与众不同?
I see many examples about multimap but did not understand why Google Gauva is different?
Multimap<Integer, Set<String>> option4 = HashMultimap.create(); // Gauva
Map<Integer, Set<String>> opt = new HashMap<Integer, Set<String>>(); //Core Java
以上两者对于保存数据的行为是否相同或不同?
Is both above are behave same for holding data or different?
推荐答案
A MultiMap< A,B>
关联类型的键A的值为 Collection< B>
(因此名称为MultiMap)
A MultiMap<A, B>
associates a key of type A with a value of type Collection<B>
(hence the name MultiMap)
A Map< A,B>
将类型A的键与类型B的值相关联。
A Map<A, B>
associates a key of type A with a value of type B.
所以, MultiMap< Integer,Set< String>>
可以被视为 Map< Integer,Collection< Set< String>>
。这应该是显而易见的,阅读 api文档。
So, a MultiMap<Integer, Set<String>>
can be viewed as a Map<Integer, Collection<Set<String>>
. This should be obvious by reading the api documentation.
这篇关于HashMap和HashMultimap有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!