簡體   English   中英

遍歷Multimap(Guava)

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM