我正在尝试使用java 8来解决以下问题.说我有以下(A并且B是自定义类)
ArrayList<A> skills;
HashSet<B> workCenters;
Run Code Online (Sandbox Code Playgroud)
我需要做的是找出a.getDepartment()一个String也包含B哪个值的方法还有一个方法String getDepartment()然后将它们收集到新的方法中List<A>.
我试过这样的:
List<A> collect = skills.stream()
.filter(s -> workCenters.contains(s.getDepartment())
.collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
但在这种情况下,我没有做对,因为我无法getDepartment()从中检索workCenters.什么是正确的解决方案?