2014-07-21 42 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