Skip to content

Commit c1612bd

Browse files
committed
Java 8 migration, use method reference for more readable code.
1 parent 8885855 commit c1612bd

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

Others/TopKWords.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public static void main(String[] args) {
7070

7171
// sort by lambda valueComparator
7272
list.sort(Comparator.comparing(
73-
m -> m.getValue())
73+
Map.Entry::getValue)
7474
);
7575

7676
Scanner input = new Scanner(System.in);

Sorts/CountingSort.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public <T extends Comparable<T>> List<T> sort(List<T> list) {
5656
**/
5757
private static <T extends Comparable<T>> List<T> streamSort(List<T> list) {
5858
return list.stream()
59-
.collect(toMap(k -> k, v -> 1, (v1, v2) -> v1 + v2, TreeMap::new))
59+
.collect(toMap(k -> k, v -> 1, Integer::sum, TreeMap::new))
6060
.entrySet()
6161
.stream()
6262
.flatMap(entry -> IntStream.rangeClosed(1, entry.getValue()).mapToObj(t -> entry.getKey()))

0 commit comments

Comments
 (0)