4

I have a method that takes List<String> locations as a parameter. I am populating a list of users in the same method based on a particular condition. Now what I want is, the user should be present in this locations. In short, the user is valid iff user's location is present in the list of locations provided. locations.

This is my current code:

primaryList.stream()
        .filter(some_pattern_matching)[.MATCH THE LOCATION HERE]
        .map(user -> user.getNames())
        .collect(toList())

is there any way to say locations.contains(user -> user.getLocation()) OR user -> user.getLocation().isPresentIn(locations) OR have locations converted into one more stream and then do matching?

This is my current code:

 .filter(locations.stream().filter(loc -> loc.equalsIgnoreCase(s.getLocation())))

which of course does not compile.

2
  • Could you provide some minimal working example of your code? Commented May 10, 2017 at 11:23
  • 2
    the user is valid iff user's location is present in the list of locations provided: so, boolean userIsValid = locations.contains(user.getLocation())? Is that what you want? If not, provide the method you want to implement, with its arguments, return type, and javadoc, because it's quite unclear. Commented May 10, 2017 at 11:27

1 Answer 1

5

Do you mean this:

.filter(user -> locations.contains(user.getLocation())
Sign up to request clarification or add additional context in comments.

1 Comment

This is case senstive. What he is doing is case senstive check

Your Answer

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