Suppose we have an Employee class, with attributes employee number, name, and salary. We
then create some Employee objects, and then add these to a SorteclSet Collection. To keep
these in a sorted order, we must implement the Comparable interface compareTo method. This
method will define the sort order. The listing shows how we might do this for the Employee
class.
Employee
1 class Employee implements Comparable {
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
int empNumber;
String name; ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.