2
我有多重映射,我想將它切成使用上鍵兩個謂詞兩個不同的地圖:的Java:切片番石榴多重映射
A -> keyPred1(K) -> A_1
A -> keyPred2(K) -> A_2
在我這樣做讓所有值的瞬間,用過濾它keyPred1/keyPred2和重建從屈德寧一遍值:
values1 = a.entries().stream()
.filter(e -> keyPred1(e.getKey()))
.collect(Collectors.toList());
a1 = rebuildMapFromValues(values1);
這沒關係,但還是看起來有點笨重。有沒有辦法以更聰明的方式解決問題?
https://google.github.io/guava/releases/snapshot/api/docs/com/google/common/collect/Multimaps.html#filterKeys-com.google.common.collect。 Multimap-com.google.common.base.Predicate- –
@JBNizet獲得100%滿意答案! –