在Java流中,PEEK真的只用于调试吗?
peek()
Consumer<Account> login = account -> account.login();
Predicate<Account> loggedIn = account -> account.loggedIn();
List<Account> accounts; //assume it's been setupList<Account> loggedInAccount = accounts.stream() .peek(login) .filter(loggedIn) .collect(Collectors.toList());
.filter(account -> { account.login(); return account.loggedIn(); })
慕娘9325324
梦里花落0921
相关分类