wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Iterator.remove() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Iterator.remove()" Watch "Iterator.remove()" New topic
Author

Iterator.remove()

Amirtharaj Chinnaraj
Ranch Hand

Joined: Sep 28, 2006
Posts: 236
hi guys i want to know what is the problem in this progam

public static void main(String as[])
{
Collection c = new ArrayList();//line 1
c.add("one");
c.add("two");
c.add("three");
c.add(null);
c.add(null);
System.out.println(" size "+c.size());
Iterator it=c.iterator();
while(it.hasNext())
{
it.hasNext();
it.remove();
}

System.out.println(" size "+c.size());

}

when i run this progam iam getting following exception
Exception in thread "main" java.lang.IllegalStateException
at java.util.AbstractList$Itr.remove(Unknown Source)
at src.com.cc.main(cc.java:23)

also i changed line 1 to ArrayList c = new ArrayList();
but still iam getting this error

looking for your replies
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
should be

and also
hi guys i want to know what is the problem in this progam
should be
Hi guys I want to know please what is the problem in this program

[ October 14, 2008: Message edited by: Charles Lyons ]

Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Iterator.remove()
 
Similar Threads
Generics Doubt (Casting)
problem
Warnings during Generic assignments
Doubts regarding ArrayLists
from mock test