If you have a ConcurrentMap , you can simply create a stream of your records by calling entrySet() and then stream() and save the records in which the value is longer than 4 by applying filter . Finally, you can reassemble it in ConcurrentMap with the built-in Collectors.toConcurrentMap .
ConcurrentMap<String, LinkedList<String>> map = new ConcurrentHashMap<>(); ConcurrentMap<String, LinkedList<String>> result = map.entrySet() .stream() .filter(e -> e.getValue().size() > 4) .collect(Collectors.toConcurrentMap(Map.Entry::getKey, Map.Entry::getValue));
Alternatively, you can do this locally by changing the map with
map.values().removeIf(l -> l.size() <= 4);
source share