| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,8 @@ | |||
| 4 | 4 | import java.util.Collections; | |
| 5 | 5 | import java.util.Comparator; | |
| 6 | 6 | import java.util.List; | |
| 7 | + import java.util.Objects; | ||
| 8 | + import java.util.Optional; | ||
| 7 | 9 | ||
| 8 | 10 | /** | |
| 9 | 11 | * @author Benjamin Winterberg | |
@@ -37,6 +39,14 @@ public int compare(String a, String b) { | |||
| 37 | 39 | List<String> names2 = Arrays.asList("peter", null, "anna", "mike", "xenia"); | |
| 38 | 40 | names2.sort(Comparator.nullsLast(String::compareTo)); | |
| 39 | 41 | System.out.println(names2); | |
| 42 | + | ||
| 43 | + List<String> names3 = null; | ||
| 44 | + | ||
| 45 | + Optional.ofNullable(names3).ifPresent(list -> list.sort(Comparator.naturalOrder())); | ||
| 46 | + | ||
| 47 | + System.out.println(names3); | ||
| 48 | + | ||
| 49 | + Objects.nonNull(names3); | ||
| 40 | 50 | } | |
| 41 | 51 | ||
| 42 | 52 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments