Prefer concise code
- less code, faster to write,
- reduce the chance to make mistake
Array to set
Arrays.stream(wrapperArray).collect(Collectors.toSet())
Arrays.stream(primitiveArray).boxed().collect(Collectors.toSet())
count.put(word, count.getOrDefault(word, 0) + 1);
Map<String, Long> counted = list.stream()
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
Map<Character, Long> astring.chars().mapToObj(ch -> (char) ch)
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
char[] to Stream
Stream<Character> stream = CharBuffer.wrap(list).chars().mapToObj(ch -> (char)ch);
Stream.of(int1, int2, ...).min(Integer::compare).get();
Character.isLetter/isWhitespace
Arrays.toString(array)
https://leetcode.com/problems/expressive-words/solution/
for (int i = 0; i < N; ++i) {
if (i == N-1 || ca[i] != ca[i+1]) {
sb.append(ca[i]);
counts.add(i - prev);
prev = i;
}
}