- Map.putIfAbsent method could be used to replace the code like this:
if (!map.containsKey(aKey)) {
map.put(aKey, aValue);
}
- Map.getOrDefault method could be used to replace the code like this:
aValue = map.get(aKey);
if (aValue == null) {
aValue = "none";
}
- Map.computeIfAbsent method could be used to replace the code like this:
List<String> list = map.get(key);
if (list == null) {
list = new ArrayList<>();
map.put(key, list);
}
- Collection.removeIf method could be used to replace the code like this:
for (Iterator<String> it = collection.iterator(); it.hasNext(); ) {
String aValue = it.next();
if(shouldBeRemoved(aValue)) {
it.remove();
}
}
- List.sort instance method could be used to replace Collections.sort static method