我有此代码:
for (UserDTO usersList:userRepo.getContent()) {
Set<String> str2 = new HashSet<>();
for (String authority:usersList.getAuthorities()) {
if(!authority.equals(AuthoritiesConstants.ADMIN) && !authority.equals(AuthoritiesConstants.USER)){
str2.add(authority);
}
}
usersList.getAuthorities().removeAll(str2);
}
是否可以将其简化为lambda表达式?
答案 0 :(得分:4)
您似乎在寻找removeIf
为:
userRepo.getContent().forEach(usersList ->
usersList.getAuthority()
.removeIf(authority ->
!authority.equals(AuthoritiesConstants.ADMIN) && !authority.equals(AuthoritiesConstants.USER)));