The requirement is to stream a Set of Object, filter on some criteria, and collect only the employeeID in a Set of String
class Employee {
private String empId;
private int type;
public int getType() {
return type;
}
public String getEmpId() {
return empId;
}
}
While filtering the following statement
employees.stream().filter(x-> x.getType() == 1).collect(Collectors.toSet());
returns a Set<Employee>
instead i want to only collect empId i.e. Set<String>
Note: Cannot make instance variable anything other than private.
Employee
toString