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:
parent
0f0908bc18
commit
784fb624c1
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue