假设我有一个包含其数据的员工列表 emp名称 经理 emp领导 emp项目 恩乐队 ......
那么如何为每个项目创建一个输出....对经理的名称进行排序并显示.package com.office.code;
公共类员工{
int empno;
String empname;
String empmanager;
String empproject;
String emplead;
String empband;
public Employee(int empno, String empname, String empmanager, String empproject, String emplead,
String empband) {
super();
this.empno = empno;
this.empname = empname;
this.empmanager = empmanager;
this.empproject = empproject;
this.emplead = emplead;
this.empband = empband;
}
} `
至于: - project1
manager1 name1 lead1 band1
manager2 name2 lead2 band2
manager3 name3 lead3 band3
答案 0 :(得分:0)
据我所知,这就是你想要的:
public void sort(ArrayList<Employee> employees){
ArrayList<String> projects=new ArrayList<>();
for(Employee employee:employees){
if(!projects.contains(employee.empproject)) {
for (Employee employe : employees) {
if (employee.empproject.equals(employe.empproject)) {
System.out.println(employe.empname);
//.
//.
//.
//for all the fields
}
}
projects.add(employee.empproject);
}
}
}
}
请尝试一下,告诉我它是否正常。