List<emp1> empList=new ArrayList<>();
empList.add(new emp1(1,"code1","a1"));
empList.add(new emp1(2,"code2","a2"));
Set<emp1> empSet=new HashSet<>();
empSet.add(new emp1(1,"code3","a3"));
for(emp1 e:empList) {
for(emp1 a:empSet) {
if(e.getB().equals(a.getB())||e.getA()==a.getA()||e.getC().equals(a.getC())) {
System.out.println("equals");
}
}
}
class emp1{
int a;
String b;
String c;
如何使用lambda或任何其他更好的方法实现这一目标?它应该比较列表中的每个元素来设置并告诉它是否存在?需要比较每个元素a,b,c,如果存在它应该返回等于
即使他对于每个人都没有多大意义,但你可能会达到:
empList.stream()
.filter(empSet::contains)
.map(a -> "equals")
.forEach(System.out::println);