Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Tim Cooke
Campbell Ritchie
paul wheaton
Ron McLeod
Devaka Cooray
Sheriffs:
Jeanne Boyarsky
Liutauras Vilda
Paul Clapham
Saloon Keepers:
Tim Holloway
Carey Brown
Piet Souris
Bartenders:
Forum:
Programmer Certification (OCPJP)
problem with advance for loop
vineet walia
Ranch Hand
Posts: 140
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
import java.util.*; class class14 { public static Iterator reverse(List list) { Collections.reverse(list); return list.iterator(); } public static void main(String[] args) { List list = new ArrayList(); list.add(" 1"); list.add("2"); list.add("3"); for (Object obj: reverse(list)) System.out.print(obj + ","); } }
please explain whats wrong with this for loop
We can use for loop in case of array and instance of iterator
What I am not getting this code please explain this code please explain?
Deepak Bala
Bartender
Posts: 6663
5
I like...
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You should
iterate over the list, not the iterator itself
public class IteratorTest { public static void reverse(List list) { Collections.reverse(list); } public static void main(String[] args) { List list = new ArrayList(); list.add(" 1"); list.add("2"); list.add("3"); reverse(list); for (Object obj : list) System.out.print(obj + ","); } }
[EDIT]
Removed extra whitespaces in code
SCJP 6 articles
-
SCJP 5/6 mock exams
-
More SCJP Mocks
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
ArrayList with Iterator new*
Doubt i a generics question
Printing a List backwards
help me
More...