diff --git a/core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/java/list/RemoveFromList.java b/core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/java/list/RemoveFromList.java index 7c23d1c978..df9b3d987d 100644 --- a/core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/java/list/RemoveFromList.java +++ b/core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/java/list/RemoveFromList.java @@ -27,13 +27,12 @@ public class RemoveFromList { while (iterator.hasNext()) { if (iterator.next().equals("Boxing")) { iterator.remove(); + break; } } // ArrayList removeIf method (Java 8) - for (int i = 0; i < sports.size(); i++) { - sports.removeIf(p -> p.equals("Cycling")); - } + sports.removeIf(p -> p.equals("Cycling")); System.out.println("List after removing: " + sports); }