美文网首页
判断公司中是否不存在薪资小于2000的员工?

判断公司中是否不存在薪资小于2000的员工?

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

    import java.util.List;
    import java.util.Optional;
    import java.util.stream.Stream;
    public class FindFirstDemo {
    public static void main(String[] args) {
    // 获取公共类的测试数据
    List<Employee> list = Employee.getEmpList();
    Stream<Employee> stream = list.stream(); // 获取集合流对象
    // 过滤出21岁的员工
    stream = stream.filter(people -> people.getAge() == 21);
    Optional<Employee> young = stream.findFirst(); // 获取第一个元素
    Employee emp = young.get(); // 获取员工对象
    System.out.println(emp); // 输出结果
    }
    }
    ====
    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);// 输出结果
    }
    }

    相关文章

      网友评论

          本文标题:判断公司中是否不存在薪资小于2000的员工?

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