Last active
May 5, 2017 13:11
-
-
Save iyengarajay/5a220d7b7ac4dcc095ec25be3de47503 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package blog; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class RemoveItemsEnhancedForModified { | |
private static List<Person> persons = new ArrayList<>(); | |
private static void initialize() { | |
persons.add(new Person("Rahul", 25, Gender.MALE, Citizenship.INDIA)); | |
persons.add(new Person("Sally", 21, Gender.FEMALE, Citizenship.USA)); | |
persons.add(new Person("Ben", 35, Gender.MALE, Citizenship.CANADA)); | |
persons.add(new Person("Wayne", 30, Gender.MALE, Citizenship.UK)); | |
persons.add(new Person("ShaneYoung", 18, Gender.MALE, Citizenship.AUSTRALIA)); | |
persons.add(new Person("Kimmo", 17, Gender.MALE, Citizenship.FINLAND)); | |
persons.add(new Person("Simo", 17, Gender.MALE, Citizenship.FINLAND)); | |
} | |
public static void main(String[] args) { | |
initialize(); | |
removeIllegalUsingEnhancedForLoop(); | |
System.out.println(persons); | |
} | |
private static void removeIllegalUsingEnhancedForLoop() | |
{ | |
for (Person p : persons) | |
{ | |
if (p.getAge() < 18) | |
{ | |
persons.remove(p); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment