2014-07-21 39 views
0

我有一个Multimap多次保存自定义对象(地点和事件)下的“地点”和“事件”的关键值下,我有地名和事件名称(干将)。如何在遍历Multimap时访问这些值。迭代通过Multimap(番石榴)

回答

0

你可以做,

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