This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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


Amirtharaj Chinnaraj
Ranch Hand

Joined: Sep 28, 2006
Posts: 241
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
System.out.println(" size "+c.size());
Iterator it=c.iterator();

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)

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

looking for your replies
Charles Lyons
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:
subject: Iterator.remove()
It's not a secret anymore!