回答編集履歴

1

finalの付け忘れ

2016/12/22 17:23

投稿

raccy
raccy

スコア21735

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
- long count = list.stream().filter((str) -> str.startsWith("h")).count();
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 = list.stream().reduce(
108
-
109
- new SimpleImmutableEntry<Long, List<String>>(new Long(0),
110
-
111
- Collections.emptyList()),
112
-
113
- (acc, str)
114
-
115
- -> {
116
-
117
- final Long accCount = acc.getKey();
118
-
119
- final Stream<String> accStream = acc.getValue().stream();
120
-
121
- final BiFunction<Boolean, String,
122
-
123
- SimpleImmutableEntry<Long, List<String>>>
124
-
125
- createPair = (incr, s)
126
-
127
- -> new SimpleImmutableEntry<Long, List<String>>(
128
-
129
- incr ? accCount : accCount + 1,
130
-
131
- Stream.concat(accStream, Stream.of(s))
132
-
133
- .collect(Collectors.toList()));
134
-
135
-
136
-
137
- return str.startsWith("h") ? createPair.apply(true, str.substring(1))
138
-
139
- : createPair.apply(false, str);
140
-
141
- },
142
-
143
- (a, b)
144
-
145
- -> new SimpleImmutableEntry<Long, List<String>>(
146
-
147
- a.getKey() + b.getKey(),
148
-
149
- Stream.concat(a.getValue().stream(), b.getValue().stream())
150
-
151
- .collect(Collectors.toList()))
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