我有一个以List<String> locations
为参数的方法。我根据特定条件在同一方法中填充用户列表。现在我想要的是,用户应该出现在这个位置。简而言之,如果用户的位置存在于提供的位置列表中,则用户有效。位置。
这是我目前的代码:
primaryList.stream()
.filter(some_pattern_matching)[.MATCH THE LOCATION HERE]
.map(user -> user.getNames())
.collect(toList())
有没有办法说locations.contains(user -> user.getLocation())
或者
user -> user.getLocation().isPresentIn(locations)
或者将位置转换为另一个流然后进行匹配?
这是我目前的代码:
.filter(locations.stream().filter(loc -> loc.equalsIgnoreCase(s.getLocation())))
当然不能编译。
答案 0 :(得分:4)
你的意思是:
.filter(user -> locations.contains(user.getLocation())