my dog learned polymorphism
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes ArrayList with Iterator new* 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 "ArrayList with Iterator new*" Watch "ArrayList with Iterator new*" New topic

ArrayList with Iterator new*

Ektaa Gargg

Joined: Mar 08, 2008
Posts: 9
What changes should i make in the below code so that it compiles & runs successfully :

Also i am looking forward to use only for-loop both normal and the enhanced for loop and not the while-loop to traverse through the list.

class x {
public static Iterator reverse(List list){
return list.iterator();

public static void main(String [] args){
List list = new ArrayList();
for(Object obj:reverse(list))
System.out.print(obj + " " );

Ekta Garg<br />(Never say Die,Life is too short to be disheartened.)
Ashok Kumar Babu
Ranch Hand

Joined: Jul 25, 2006
Posts: 129

public interface Iterable<T>

Implementing this interface allows an object to be the target of the "foreach" statement.

Check this implementation

Ashok<br /> <br />SCJP 91%<br />SCWCD 88%
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Ektaa Gargg:
What changes should i make in the below code so that it compiles & runs successfully :

Did you try to compile it?
If so, did it compile?
If not, what error message(s) did the compiler return?

If you did compile it, did you try to run it?
If so, did it work?
If not, what exceptions were thrown?

We're happy to help but first we like to see some effort on your part.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: ArrayList with Iterator new*
It's not a secret anymore!