按计数过滤 Guava HashMultimap 键
我创建了以下类型的哈希多重映射:键作为一对字符串,字符串和值一样长。
HashMultimap<Pair<String, String>, Long> hm = HashMultimap.create();
我使用 put 函数在表中插入了一些值。
现在我想找到所有具有多个值的键。我想使用 for 循环来迭代所有键并找到那些具有多个值的键。请帮助我我该怎么做?
I have created a hash multi map of following type: key as a pair of string, string and value as long.
HashMultimap<Pair<String, String>, Long> hm = HashMultimap.create();
I have inserted some values in the table using put function.
Now I want to find all those keys which have multiple values. I want to use for loop to iterate over all keys and find those keys which have multiple values. Please help me how can i do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
马特已经涵盖了程序方式。更实用的方法(仍然很冗长,因为 Java 还没有闭包)是这样的:
我面前没有库和编译器,所以可能存在一些未解决的泛型问题。
Matt has the procedural way covered. The more functional approach (still verbose since Java doesn't have closures yet) would be something like this:
I don't have the library and a compiler in front of me so there are probably some unresolved generics problems with that.
这应该比 Matt 的版本更有效,因为没有使用键查找:
This should be a bit more efficient than Matt's version as no lookup by keys is used: