回答編集履歴
1
コメントを受けて追記
answer
CHANGED
@@ -25,4 +25,36 @@
|
|
25
25
|
.forEach(System.out::println); // 3(a) -> 1(b) -> 4(c) -> 2(d) の順にソートされてる
|
26
26
|
}
|
27
27
|
}
|
28
|
+
```
|
29
|
+
|
30
|
+
----
|
31
|
+
|
32
|
+
MapのvalueだけのListにしたいなら↓
|
33
|
+
|
34
|
+
```java
|
35
|
+
import java.util.*;
|
36
|
+
import java.util.stream.Collectors;
|
37
|
+
|
38
|
+
class Playground {
|
39
|
+
private static class Obj {
|
40
|
+
public String val;
|
41
|
+
|
42
|
+
public Obj(String val) {
|
43
|
+
this.val = val;
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
public static void main(String[ ] args) {
|
48
|
+
Map<String, Playground.Obj> map = new HashMap();
|
49
|
+
|
50
|
+
map.put("1", new Playground.Obj("b"));
|
51
|
+
map.put("2", new Playground.Obj("d"));
|
52
|
+
map.put("3", new Playground.Obj("a"));
|
53
|
+
map.put("4", new Playground.Obj("c"));
|
54
|
+
|
55
|
+
List<Playground.Obj> list = map.values().stream()
|
56
|
+
.sorted((e1, e2) -> e1.val.compareTo(e2.val))
|
57
|
+
.collect(Collectors.toList());
|
58
|
+
}
|
59
|
+
}
|
28
60
|
```
|