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 Iterator of an ArrayList 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 "Iterator of an ArrayList" Watch "Iterator of an ArrayList" New topic

Iterator of an ArrayList

Joey Sanchez
Ranch Hand

Joined: Jun 23, 2011
Posts: 88

Where does the error come from?

Henry Wong

Joined: Sep 28, 2004
Posts: 20535

Joey Sanchez wrote:Where does the error come from?

You are trying to instantiate an object of the myL.interator class. Notice the "new" operator.... and it is complaining that it can't find such a class.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Zeeshan Sheikh
Ranch Hand

Joined: Nov 20, 2011
Posts: 144

Iterator i = new myL.iterator(); //Wrong Statement

Just take new operator out

Iterator i = myL.iterator(); //Right Statement

You are accessing iterator method of ArrayList so there is no need for 'new' operator. Hope this helps.

MySQL Blog
I agree. Here's the link:
subject: Iterator of an ArrayList
It's not a secret anymore!