List
私がEmployee
オブジェクトを持っているとしましょう。Employee
オブジェクトには、オブジェクトgetDepartment
を返すメソッドがありますDepartment
。Employee
そのリストを繰り返し処理して、 sが最も多い部門(つまり、Department
オブジェクトが最も頻繁に返される)を見つけたいと思いますgetDepartment
。これを行うための最速の方法は何ですか?
public class Employee{
static allEmployees = new ArrayList<Employee>();
int id;
Department department;
public Employee(int id, Department department){
this.id = id;
this.department = department;
allEmployees.add(this);
}
public Department getDepartment(){
return department;
}
public static List<Employee> getAllEmployees(){
return allEmployees;
}
}
public class Department{
int id;
String name;
public Department(int id){
this.id = id;
}
public String getName(){
return name;
}
}
同数の従業員がいる2つの部門がある場合、どちらが返されるかは問題ではありません。
ありがとう!