首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >遍历多映射(Guava)

遍历多映射(Guava)
EN

Stack Overflow用户
提问于 2014-07-21 19:47:28
回答 1查看 176关注 0票数 0

我有一个Multimap,它在" place“和" event”的键值下多次保存自定义对象(地点和事件),在这些对象中,我有地点名称和事件名称(getters)。如何在遍历Multimap时访问这些值。

EN

回答 1

Stack Overflow用户

发布于 2014-07-21 20:03:04

你能做到的,

代码语言:javascript
复制
Collection<Object> values = map.get(key);
checkState(values.size() == 2, String.format("Found %d values for key %s", values.size(), key));

return values.iterator().next(); // to get the first

Iterator<Object> it = values.iterator();
it.next(); // move the pointer to the second object
return it.next(); // get the second object

检查- retrieving-specific-values-in-multimap

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24864348

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档