[英]Iterating through Multimap (Guava)
我有一個Multimap,它在“ place”和“ event”的鍵值下多次保存自定義對象(“ Places”和“ Events”),在這些對象中,我具有地名和事件名(“ getters”)。 遍歷Multimap時如何訪問這些值。
你可以做,
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
檢查在multimap中檢索特定值 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.