File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes collection class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "collection class" Watch "collection class" New topic

collection class

kuchi DASS

Joined: Sep 02, 2003
Posts: 6
Hi i tried to run this simple program
But ran with an error. please suggest

import java.util.*;
public class Collectionusage
int array[] = { 1,2,3,4 };
Collection col = new ArrayList();
Iterator iter;
public Collectionusage()

public void initialise()
iter = col.iterator();
for(int i=0;i<array.length;i++)
col.add(new Integer(array[i]));

public void read()

while (iter.hasNext())
Integer element = (Integer);
//System.out.println("value is"+element.intValue());
public static void main(String arg[])
Collectionusage test = new Collectionusage();
it complies fine but gives a run time error as follows
java.util.ConcurrentModificationException at java.util.AbstractList$Itr.checkForComodification( at java.util.AbstractList$ at at Collectionusage.main( Exception in thread "main" Process Exit...
Yosi Hendarsjah
Ranch Hand

Joined: Oct 02, 2003
Posts: 166
Hi Kuchi!
The member variable iter is initialised before the Collection col is populated. So iter represents an empty collection. Then col is populated. Now there is an inconsistence between iter and col. So when the method read() try to iterate iter,
ConcurrentModificationException is thrown.
Sean Walker
Ranch Hand

Joined: Feb 04, 2004
Posts: 64
I guess I'm so preoccupied with problem solving (due to my efforts on SCJP) everything I see presents itself as an other problem to solve!
So, what's with your name? Kuchi -your first 'name'- happens to mean mouth in Japanese. Of course this might just be coincidence. Anyway, what on earth does DASS mean?

Sean Walker<br />PMP, SCEA, SCWCD, SCJP
Abdulla Mamuwala
Ranch Hand

Joined: Jan 09, 2004
Posts: 225
I am sorry, Sean this forum is for discussing topics related to SCJP and not posting personal messages.
Thank you.
Sean Walker
Ranch Hand

Joined: Feb 04, 2004
Posts: 64
You are quite correct, my mistake. I'll take all future 'personal' comments elsewhere. However, forgive me if I make one last 'personal' observation: I really think you need to get a lot more fibre in your diet man.
I agree. Here's the link:
subject: collection class
It's not a secret anymore!