break added to avoid unnecessary loop iterations. Get rid of for since a loop is not needed for removeIf method

This commit is contained in:
David Calap 2019-09-02 14:02:25 +02:00
parent 0f0908bc18
commit 784fb624c1
1 changed files with 2 additions and 3 deletions

View File

@ -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);
}