2

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 ?

1
  • Well this code doesn't even compile. Also, it's not clear what part you'd want to create a lambda from. Commented Mar 7, 2019 at 10:22

1 Answer 1

4

You seem to be looking for removeIf as :

userRepo.getContent().forEach(usersList -> 
        usersList.getAuthority()
                .removeIf(authority -> 
                        !authority.equals(AuthoritiesConstants.ADMIN) && !authority.equals(AuthoritiesConstants.USER)));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.