回答編集履歴
1
finalの付け忘れ
test
CHANGED
@@ -90,7 +90,9 @@
|
|
90
90
|
|
91
91
|
public static Long checkAndDelSeparate(List<String> list) {
|
92
92
|
|
93
|
+
final long count =
|
94
|
+
|
93
|
-
|
95
|
+
list.stream().filter((str) -> str.startsWith("h")).count();
|
94
96
|
|
95
97
|
list.replaceAll((str) -> str.startsWith("h") ? str.substring(1) : str);
|
96
98
|
|
@@ -104,55 +106,59 @@
|
|
104
106
|
|
105
107
|
public static Long checkAndDelOnce(List<String> list) {
|
106
108
|
|
107
|
-
SimpleImmutableEntry<Long, List<String>> result =
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
(
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
final
|
120
|
-
|
121
|
-
final
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
.co
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
(a,
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
S
|
150
|
-
|
151
|
-
.
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
)
|
109
|
+
final SimpleImmutableEntry<Long, List<String>> result =
|
110
|
+
|
111
|
+
list.stream().reduce(
|
112
|
+
|
113
|
+
new SimpleImmutableEntry<Long, List<String>>(
|
114
|
+
|
115
|
+
new Long(0), Collections.emptyList()),
|
116
|
+
|
117
|
+
(acc, str)
|
118
|
+
|
119
|
+
-> {
|
120
|
+
|
121
|
+
final Long accCount = acc.getKey();
|
122
|
+
|
123
|
+
final Stream<String> accStream = acc.getValue().stream();
|
124
|
+
|
125
|
+
final BiFunction<Boolean, String,
|
126
|
+
|
127
|
+
SimpleImmutableEntry<Long, List<String>>>
|
128
|
+
|
129
|
+
createPair = (incr, s)
|
130
|
+
|
131
|
+
-> new SimpleImmutableEntry<Long, List<String>>(
|
132
|
+
|
133
|
+
incr ? accCount : accCount + 1,
|
134
|
+
|
135
|
+
Stream.concat(accStream, Stream.of(s))
|
136
|
+
|
137
|
+
.collect(Collectors.toList()));
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
return str.startsWith("h")
|
142
|
+
|
143
|
+
? createPair.apply(true, str.substring(1))
|
144
|
+
|
145
|
+
: createPair.apply(false, str);
|
146
|
+
|
147
|
+
},
|
148
|
+
|
149
|
+
(a, b)
|
150
|
+
|
151
|
+
-> new SimpleImmutableEntry<Long, List<String>>(
|
152
|
+
|
153
|
+
a.getKey() + b.getKey(),
|
154
|
+
|
155
|
+
Stream.concat(a.getValue().stream(), b.getValue().stream())
|
156
|
+
|
157
|
+
.collect(Collectors.toList()))
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
);
|
156
162
|
|
157
163
|
final Iterator<String> itr = result.getValue().iterator();
|
158
164
|
|