回答編集履歴

1

コメントを受けて追記

2018/09/08 12:54

投稿

spookybird
spookybird

スコア1803

test CHANGED
@@ -53,3 +53,67 @@
53
53
  }
54
54
 
55
55
  ```
56
+
57
+
58
+
59
+ ----
60
+
61
+
62
+
63
+ MapのvalueだけのListにしたいなら↓
64
+
65
+
66
+
67
+ ```java
68
+
69
+ import java.util.*;
70
+
71
+ import java.util.stream.Collectors;
72
+
73
+
74
+
75
+ class Playground {
76
+
77
+ private static class Obj {
78
+
79
+ public String val;
80
+
81
+
82
+
83
+ public Obj(String val) {
84
+
85
+ this.val = val;
86
+
87
+ }
88
+
89
+ }
90
+
91
+
92
+
93
+ public static void main(String[ ] args) {
94
+
95
+ Map<String, Playground.Obj> map = new HashMap();
96
+
97
+
98
+
99
+ map.put("1", new Playground.Obj("b"));
100
+
101
+ map.put("2", new Playground.Obj("d"));
102
+
103
+ map.put("3", new Playground.Obj("a"));
104
+
105
+ map.put("4", new Playground.Obj("c"));
106
+
107
+
108
+
109
+ List<Playground.Obj> list = map.values().stream()
110
+
111
+ .sorted((e1, e2) -> e1.val.compareTo(e2.val))
112
+
113
+ .collect(Collectors.toList());
114
+
115
+ }
116
+
117
+ }
118
+
119
+ ```