I am reading “The Java Tutorial Continued, The Rest of JDK /Mary Campione,enter code here
…”.
In collections chapter I’ve encountered the problems and I can’t understand them as followed:
We have a class called EmployeeRecord:
**public class EmployeeRecord implements Comparable {
public Name name();
public int employeeNumber();
public Date hireDate();
...
}**
Let’s assume that the natural ordering of EmployeeRecord objects is Name-ordering
import java.util.*;
class EmpSort {
static final Comparator SENIORITY_ORDER = new Comparator() {
public int compare(Object o1, Object o2) {
EmployeeRecord r1 = (EmployeeRecord) o1;
EmployeeRecord r2 = (EmployeeRecord) o2;
return r2.hireDate().compareTo(r1.hireDate());
}
};
**static final Collection employees = ... ;** // Employee Database
public static void main(String args[]) {
List emp = new ArrayList(employees);
Collections.sort(emp, SENIORITY_ORDER);
System.out.println(emp);
}
}
I have problem with EmployeeRecord class, I mean what is the rest of the EmployeeRecord class and also the second problem is what it should be the rest of Emplyee Database, I mean how could I add EmployeeRecord to the Employees Collection?
I have problem with the rest of The EmployeeRecord class and the rest of Cillection employee.
Ali Mir Mohamad Ali EE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.