Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to remove the element with Iterators

807603Feb 7 2008 — edited Feb 7 2008
I have a programm like this

Vector ts = new Vector();
ts.add("abc"); ts.add("abd");
Iterator it = ts.iterator();
ts.remove("abc");
it.remove();
while(it.hasNext())
{ System.out.println("val = " + it.next()); }

What is the problem if I use remove with iterator. It is giving the error java.lang.IllegalStateException. Can somebody tell me what is wrong with this.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 6 2008
Added on Feb 7 2008
1 comment
271 views