diff --git a/src/main/java/org/apache/commons/collections4/list/CursorableLinkedList.java b/src/main/java/org/apache/commons/collections4/list/CursorableLinkedList.java index ddc63dd1a..ea02b2192 100644 --- a/src/main/java/org/apache/commons/collections4/list/CursorableLinkedList.java +++ b/src/main/java/org/apache/commons/collections4/list/CursorableLinkedList.java @@ -274,12 +274,7 @@ public class CursorableLinkedList extends AbstractLinkedList implements Se protected void registerCursor(final Cursor cursor) { // We take this opportunity to clean the cursors list // of WeakReference objects to garbage-collected cursors. - for (final Iterator>> it = cursors.iterator(); it.hasNext();) { - final WeakReference> ref = it.next(); - if (ref.get() == null) { - it.remove(); - } - } + cursors.removeIf(ref -> ref.get() == null); cursors.add(new WeakReference<>(cursor)); } diff --git a/src/main/java/org/apache/commons/collections4/set/ListOrderedSet.java b/src/main/java/org/apache/commons/collections4/set/ListOrderedSet.java index ce9d3007a..d9e89c4a4 100644 --- a/src/main/java/org/apache/commons/collections4/set/ListOrderedSet.java +++ b/src/main/java/org/apache/commons/collections4/set/ListOrderedSet.java @@ -261,14 +261,10 @@ public class ListOrderedSet if (result == false) { return false; } - if (decorated().size() == 0) { + if (decorated().isEmpty()) { setOrder.clear(); } else { - for (final Iterator it = setOrder.iterator(); it.hasNext();) { - if (!decorated().contains(it.next())) { - it.remove(); - } - } + setOrder.removeIf(e -> !decorated().contains(e)); } return result; }