boolean isSuccess = aMap.entrySet().stream().anyMatch(entry -> {
AKey aKey= entry.getKey();
BValue bValue = bMap.get(aKey);
if (bValue == null) {
return false;
}
AValue aValue = entry.getValue();
if (compareDetail(aValue, bValue)) {
return false;
}
return true;
}
);
這段代碼總是隻循環一次,我如何循環所有元素,然後返回true,當兩個if塊假?Java 8 Stream,anyMatch
你想'所有'元素匹配你的'謂語'? – Eugene
從你的問題中不清楚輸出應該是什麼。你是否需要所有的地圖條目通過這個謂詞?你可以使用'allMatch'而不是'anyMatch'。 – Eran
@Eugene yep,如果兩個謂詞都是假的,並且我想繼續循環,並且在上一次返回true循環 –