Java 8 lambda expression for finding "contains"

java, java-8, java-stream, lambda, list

Solution

Do you mean this:

.filter(user -> locations.contains(user.getLocation())

Problem

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.

Original source