Guava MultiSet对比地图? [英] Guava MultiSet vs Map?

查看:111
本文介绍了Guava MultiSet对比地图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Multiset的理解是一个有频率的集合,但是我总是可以使用Map来表示频率,还有其他理由使用Multiset吗?

My understanding of Multiset is a set with frequency, but I can always use Map to represent the frequency, is there other reason to use Multiset?

推荐答案

Multiset< E> 优于地图< E,整数>


  • 添加尚未包含在集合中的元素时不需要特殊代码。

  • 直接处理元素数: count(E) add(E,int)等等。

  • 代码的意图更清晰。 Multiset< E> 显然将元素映射到它们的计数。 Map< E,Integer> 可以将元素映射到任意整数。

  • No special code required when adding an element that is not already in the collection.
  • Methods for handling the count of elements directly: count(E), add(E, int), etc.
  • The intention of the code is clearer. A Multiset<E> obviously maps the elements to their counts. A Map<E, Integer> could map the elements to arbitrary integers.

另见:

Multiset Javadoc

Multiset在Guava Wiki中解释

这篇关于Guava MultiSet对比地图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆