Skip to content

Commit 6a61856

Browse files
author
yennj12
committed
add
1 parent d307f62 commit 6a61856

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

leetcode_java/src/main/java/dev/Sorting/HashMapSortTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void testSortMapWithValue(){
6969
* - The lambda expression is shorthand for an anonymous inner class that implements the compare method directly.
7070
*
7171
*/
72-
72+
7373

7474
/** V1 : lambda expression */
7575
// Collections.sort(keyList, (x,y) -> {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,42 @@
11
package dev.Sorting;
22

3+
import org.junit.Test;
4+
5+
import java.util.*;
6+
37
public class ListSortTest {
8+
9+
@Test
10+
public void testSortListWithVal_1(){
11+
12+
List<Integer> list = new ArrayList<>();
13+
list.add(5);
14+
list.add(99);
15+
list.add(1);
16+
list.add(-3);
17+
18+
System.out.println(">>> (before) list = " + list);
19+
20+
// V1: lambda
21+
Collections.sort(list, (x,y) -> {
22+
int diff = y - x;
23+
return diff;
24+
});
25+
//
26+
// // V2: Comparator.compare
27+
// Collections.sort(list, new Comparator<Integer>(){
28+
// @Override
29+
// public int compare(Integer o1, Integer o2) {
30+
// //int diff = o1 - o2; // smaller first (increasing order)
31+
// int diff = o2 - o1; // bigger first, (decreasing order)
32+
//// if(diff == 0){
33+
//// return
34+
//// }
35+
// return diff;
36+
// }
37+
// });
38+
39+
System.out.println(">>> (after) list = " + list);
40+
41+
}
442
}

0 commit comments

Comments
 (0)