Mercer :
I have this code:
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);
}
it's possible to reduce this to a lambda expression ?
Naman :
You seem to be looking for removeIf
as :
userRepo.getContent().forEach(usersList ->
usersList.getAuthority()
.removeIf(authority ->
!authority.equals(AuthoritiesConstants.ADMIN) && !authority.equals(AuthoritiesConstants.USER)));