美文网首页
员工中有年龄在40或以上的吗?与公司中是否不存在薪资小于2000

员工中有年龄在40或以上的吗?与公司中是否不存在薪资小于2000

作者: 哈迪斯Java | 来源:发表于2021-12-09 20:12 被阅读0次

import java.util.List;
import java.util.stream.Stream;
public class AnyMatchDemo {
public static void main(String[] args) {
List<Employee> list = Employee.getEmpList(); // 获取公共类的测试数据
Stream<Employee> stream = list.stream(); // 获取集合流对象
// 判断员工是否有的年龄大于等于40
boolean result = stream.anyMatch(people -> people.getAge() >= 40);
System.out.println("员工中有年龄在40或以上的吗?:" + result); // 输出结果

}

}

import java.util.List;
import java.util.stream.Stream;
public class NoneMathchDemo {
public static void main(String[] args) {
List<Employee> list = Employee.getEmpList(); // 获取公共类的测试数据
Stream<Employee> stream = list.stream(); // 获取集合流对象
// 判断公司中是否不存在薪资小于2000的员工?
boolean result = stream.noneMatch(people -> people.getSalary() <2000 );
System.out.println("公司中是否不存在薪资小于2000元的员工?:" + result);// 输出结果
}
}

相关文章

网友评论

      本文标题:员工中有年龄在40或以上的吗?与公司中是否不存在薪资小于2000

      本文链接:https://www.haomeiwen.com/subject/jskbxrtx.html