2017-05-03 73 views
-1
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

+0

你想'所有'元素匹配你的'謂語'? – Eugene

+0

從你的問題中不清楚輸出應該是什麼。你是否需要所有的地圖條目通過這個謂詞?你可以使用'allMatch'而不是'anyMatch'。 – Eran

+0

@Eugene yep,如果兩個謂詞都是假的,並且我想繼續循環,並且在上一次返回true循環 –

回答

1

看來你需要嘗試allMatch來代替。

+0

我曾嘗試'allMatch',但仍然循環一次。 –

+0

@HavenLin,好吧,請你分享一下你的代碼以獲取更多細節?我的意思是'compareDetail'方法和'AKey','AValue'對象 –

+0

它太長了,我可以給你發送截圖。 –