Skip to content

Commit cc98cc2

Browse files
author
Rajeev Kumar Singh
committed
Comparable and Comparator Examples
1 parent 170f001 commit cc98cc2

File tree

2 files changed

+2
-7
lines changed

2 files changed

+2
-7
lines changed

java-comparable-comparator-examples/src/ComparableExample.java

-5
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,5 @@ public static void main(String[] args) {
1818
Collections.sort(employees);
1919

2020
System.out.println("\nEmployees (After Sorting) : " + employees);
21-
22-
// This will use the same `compareTo()` method of the `Employee` class but will reverse the order
23-
Collections.sort(employees, Comparator.reverseOrder());
24-
System.out.println("\nEmployees (After Sorting with reverseOrder)" + employees);
2521
}
26-
2722
}

java-comparable-comparator-examples/src/ComparatorExample.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ public static void main(String[] args) {
3434
// Chaining multiple Comparators
3535
// Sort by Salary. If Salary is same then sort by Name
3636
Collections.sort(employees, Comparator.comparingDouble(Employee::getSalary).thenComparing(Employee::getName));
37-
System.out.println("\nEmployees (Sorted by Salary and Id) : " + employees);
37+
System.out.println("\nEmployees (Sorted by Salary and Name) : " + employees);
3838
}
39-
}
39+
}

0 commit comments

Comments
 (0)