Skip to content

Commit 61164f2

Browse files
committed
add more comparator samples as discussed on reddit: http://redd.it/20ng6r
1 parent 040f9b9 commit 61164f2

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/com/winterbe/java8/Lambda1.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ public int compare(String a, String b) {
2929
Collections.sort(names, (a, b) -> b.compareTo(a));
3030

3131
System.out.println(names);
32+
33+
names.sort(Collections.reverseOrder());
34+
35+
System.out.println(names);
36+
37+
List<String> names2 = Arrays.asList("peter", null, "anna", "mike", "xenia");
38+
names2.sort(Comparator.nullsLast(String::compareTo));
39+
System.out.println(names2);
3240
}
3341

3442
}

0 commit comments

Comments
 (0)