Skip to content

Instantly share code, notes, and snippets.

@iyengarajay
Last active May 5, 2017 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iyengarajay/5a220d7b7ac4dcc095ec25be3de47503 to your computer and use it in GitHub Desktop.
Save iyengarajay/5a220d7b7ac4dcc095ec25be3de47503 to your computer and use it in GitHub Desktop.
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