Skip to content

Instantly share code, notes, and snippets.

@anil477
Created November 16, 2017 17:09
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 anil477/584336f9f4b8273380dc943b2f621caf to your computer and use it in GitHub Desktop.
Save anil477/584336f9f4b8273380dc943b2f621caf to your computer and use it in GitHub Desktop.
Remove From Iterator
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class DeleteTest
{
public static void main(String[] args)
{
List<Integer> l = new ArrayList<Integer>();
l.add(10);
l.add(20);
l.add(20);
l.add(30);
l.add(20);
Iterator<Integer> iter = l.iterator();
while (iter.hasNext()) {
if (iter.next().intValue() == 10) {
iter.remove();
}
}
Iterator<Integer> r = l.iterator();
while (r.hasNext()) {
System.out.println(r.next());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment