Collections. New Methods
Arrays.asList = can set, can’t add
Immutable collections
of:
List.of
Set.of
Map.of
Map.ofEntries (entry(K, V), entry(K1, V1))
New methods
List
removeIf(predicate)
????? removeIf — quadratic performance with array based lists — ArrayList, Vector, CopyOnWriteArrayList
Map
forEach
getOrDefault(key, defaultValue): replace for
if (map.contain(key)) {
return map.get(key)
}
return -1;
putIfAbsent(key, value): replace for
if (map.get(key) == null) {
map.put(key, value)
}
compute
computeIfPresent
computeIfAbsent -> don’t change map structure — Recursive update (raise Exception)
Value val = map.get(key);
if (val == null) {
val = new Value();
map.put(key. value);
} ==> map.computeIfAbsent(key, k -> new Value());
merge:
map.merge(key, value, (oldValue, newValue) - > old.value.concat("newValue"));
remove
replaceAll
ConcurrentHashMap
forEach(key, value)
search(key, value)
reduce(key,value)
+ при операциях нужно уточнять параметр threshold — порог, после которого выполнение операций будет последовательным.
Если указать 1 — максимальная параллельность,
если указать Long.MAX_VALUE — то последовательная обработка для всех.
+ reduce содержит операции, возвращающие примитивные типы — int, long, double
дополнительный метод mappingCount