[英]Guava MultiSet vs Map?
我对Multiset的理解是一个有频率的集合,但是我总是可以使用Map来表示频率,还有其他理由使用Multiset吗?
Advantages of a Multiset<E>
over a Map<E, Integer>
: Multiset<E>
优于Map<E, Integer>
优点:
count(E)
, add(E, int)
, etc. count(E)
, add(E, int)
等。 Multiset<E>
obviously maps the elements to their counts. Multiset<E>
显然将元素映射到它们的计数。 A Map<E, Integer>
could map the elements to arbitrary integers. Map<E, Integer>
可以将元素映射到任意整数。 See also: 也可以看看:
Multiset Javadoc Multiset Javadoc
Multiset explained in the Guava Wiki Multiset在Guava Wiki中进行了解释
To me, the most important point that sets Multiset
apart from a Map
is that it's a Collection
: you just put stuff into it and you can get counts later. 对我而言,将
Multiset
与Map
区别开来的最重要的一点是它是一个Collection
:你只需要把东西放进去就可以得到计数。 It conceptually fits the use cases for which it's designed where a Map
does not. 它在概念上适合于
Map
设计的用例。 For those use cases, a Map
is just a hack that kinda-sorta works OK since Java didn't provide anything more appropriate. 对于那些用例,
Map
只是一种有点排序的hack,因为Java没有提供更合适的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.