如何 return 流对象?

How to return Stream objects?

** 我刚开始研究 java 中的流,我被这个问题困住了。 在下面的代码中,我得到了 Fclass 的主要方法,我必须创建一个 class Employee,它是构造函数和 getter 方法,我还必须创建一个方法“query " 在 Fclass 中,应该 return 那些具有相同部门名称和薪水大于或等于将要给出的输入的 Employee 对象的流。我已经编写了代码,但是当我 运行 它时,它没有生成任何输出。有人能告诉我哪里出错了吗? **

import java.util.*;
import java.util.stream.*;
class Employee{
private String n;
private String d;
private int s;
    public Employee(String name, String dep, int sal) {
        this.n = name;                  //define class Employee
        this.d = dep;
        this.s = sal;
    }
    public String getname() {
        return n;
    }
    public String getdep() {
        return d;
    }
    public int getsal() {
        return s;
    }
    public String toString() {
        return n+":"+d+":"+s+" ";
    }
}//define class Employee

class FClass{
    public static Stream<Employee> query(ArrayList<Employee> eList, String d, double s) {
        Stream<Employee> emp = eList.stream().filter(x->x.getdep()==d && x.getsal() >= s);
        return emp;
    }//define method query

    
 public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        var eList = new ArrayList<Employee>();
        eList.add(new Employee("Jack", "HR", 30000));
        eList.add(new Employee("Aria", "HR", 40000));
        eList.add(new Employee("Nora", "IT", 50000));
        eList.add(new Employee("Bella", "IT", 60000));
        eList.add(new Employee("Jacob", "IT", 70000));
        eList.add(new Employee("James", "HR", 80000));
        String d = sc.next();       //read department
        double s = sc.nextInt();    //read salary
        
        var st = query(eList, d, s);
        st.forEach(n -> System.out.println(n + " "));
    }
}

在您的过滤器中,您将字符串与 ==:

进行比较

x.getdep()==d

请改用x.getdep().equals(d)