質問するログイン新規登録

回答編集履歴

1

finalの付け忘れ

2016/12/22 17:23

投稿

raccy
raccy

スコア21850

answer CHANGED
@@ -44,38 +44,41 @@
44
44
  }
45
45
 
46
46
  public static Long checkAndDelSeparate(List<String> list) {
47
+ final long count =
47
- long count = list.stream().filter((str) -> str.startsWith("h")).count();
48
+ list.stream().filter((str) -> str.startsWith("h")).count();
48
49
  list.replaceAll((str) -> str.startsWith("h") ? str.substring(1) : str);
49
50
 
50
51
  return count;
51
52
  }
52
53
 
53
54
  public static Long checkAndDelOnce(List<String> list) {
54
- SimpleImmutableEntry<Long, List<String>> result = list.stream().reduce(
55
+ final SimpleImmutableEntry<Long, List<String>> result =
56
+ list.stream().reduce(
55
- new SimpleImmutableEntry<Long, List<String>>(new Long(0),
57
+ new SimpleImmutableEntry<Long, List<String>>(
56
- Collections.emptyList()),
58
+ new Long(0), Collections.emptyList()),
57
- (acc, str)
59
+ (acc, str)
58
- -> {
60
+ -> {
59
- final Long accCount = acc.getKey();
61
+ final Long accCount = acc.getKey();
60
- final Stream<String> accStream = acc.getValue().stream();
62
+ final Stream<String> accStream = acc.getValue().stream();
61
- final BiFunction<Boolean, String,
63
+ final BiFunction<Boolean, String,
62
- SimpleImmutableEntry<Long, List<String>>>
64
+ SimpleImmutableEntry<Long, List<String>>>
63
- createPair = (incr, s)
65
+ createPair = (incr, s)
64
- -> new SimpleImmutableEntry<Long, List<String>>(
66
+ -> new SimpleImmutableEntry<Long, List<String>>(
65
- incr ? accCount : accCount + 1,
67
+ incr ? accCount : accCount + 1,
66
- Stream.concat(accStream, Stream.of(s))
68
+ Stream.concat(accStream, Stream.of(s))
67
- .collect(Collectors.toList()));
69
+ .collect(Collectors.toList()));
68
70
 
71
+ return str.startsWith("h")
69
- return str.startsWith("h") ? createPair.apply(true, str.substring(1))
72
+ ? createPair.apply(true, str.substring(1))
70
- : createPair.apply(false, str);
73
+ : createPair.apply(false, str);
71
- },
74
+ },
72
- (a, b)
75
+ (a, b)
73
- -> new SimpleImmutableEntry<Long, List<String>>(
76
+ -> new SimpleImmutableEntry<Long, List<String>>(
74
- a.getKey() + b.getKey(),
77
+ a.getKey() + b.getKey(),
75
- Stream.concat(a.getValue().stream(), b.getValue().stream())
78
+ Stream.concat(a.getValue().stream(), b.getValue().stream())
76
- .collect(Collectors.toList()))
79
+ .collect(Collectors.toList()))
77
80
 
78
- );
81
+ );
79
82
  final Iterator<String> itr = result.getValue().iterator();
80
83
  list.replaceAll((_s) -> itr.next());
81
84