Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Iterator.remove()

 
Amirtharaj Chinnaraj
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic