Created
November 16, 2017 17:09
-
-
Save anil477/584336f9f4b8273380dc943b2f621caf to your computer and use it in GitHub Desktop.
Remove From Iterator
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
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