在Java7我有這樣的代碼:如何計算與Streams謂詞匹配的元素數量?
public int getPlayersOnline() {
int count = 0;
for (Player player : players) {
if (player.isActive()) {
count++;
}
}
return count;
}
我試圖用Java 8層的功能儘可能,我怎麼能去與lambda表達式改善呢?
是''players'的Player'一個ArrayList? –