【发布时间】:2019-08-06 18:40:53
【问题描述】:
我正在处理员工的arraylist,需要按员工数量按功能使用分组,统计活跃员工和非活跃员工。我知道如何处理总数,但是我怎样才能通过函数分组处理数组列表。
public class Employee {
private String name;
private String department;
private String status;
public Employee(String name, String department, String status) {
this.setName(name);
this.setDepartment(name);
this.setStatus(status);
}
public String getName() {
return name;
}
public String getDepartment() {
return department;
}
public void setName(String name) {
this.name = name;
}
public void setDepartment(String department) {
this.department = department;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}
ArrayList<Employee> listEmployee = new ArrayList<Employee>();
listEmployee.add(new Employee("Ravi", "IT", "active"));
listEmployee.add(new Employee("Tom", "Sales", "inactive"));
listEmployee.add(new Employee("Kanna", "IT", "inactive"));
int count = 0;
for (Employee e : listEmployee) {
count++;
}
System.out.println("Count of Employees" + count);
这是我试图获取员工人数的上述代码
int count = 0;
for (Employee e : listEmployee) {
count++;
}
System.out.println("Count of Employees" + count);
请帮我按部门分组处理数据
我期待以下输出:
Department total activeCount inactiveCount
IT 2 1 1
Sales 1 0 1
【问题讨论】:
-
请给出
Employee类的代码