public int getPlayersOnline() { int count = 0; for (Player player : players) { if (player.isActive()) { count++; } } return count; }
我尽可能地使用Java 8功能,我可以用lambdas来改进这个吗?
return (int) players.stream().filter(Player::isActive).count();