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
Win a copy of
Eclipse Collections Categorically: Level up your programming game
this week in the
Open Source Projects
forum!
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:
Campbell Ritchie
Tim Cooke
paul wheaton
Ron McLeod
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
Programmer Certification (OCPJP)
Collections mock question
adam Lui
Ranch Hand
Posts: 186
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
import java.util.*; class ForTest{ static List list = new ArrayList(); static List getList() {return list;} public static void main (String[] args) { list.add("Ready"); list.add("Set"); list.add("Go"); for (List obj:getList()) //line 10 System.out.println(obj); } }
why would line 10 generate compatible error?!
sathi jogi
Greenhorn
Posts: 14
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
hi,
here you are trying to retrieve the list objects from the arraylist, that is not right, you are retrieving objects from the list,
so modify the line 10 as given below,
for (Object obj:getList()) //line 10
System.out.println(obj);
}
adam Lui
Ranch Hand
Posts: 186
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
so we use ....
for (Object obj: getlist())
wat about ...
for (ArrayList obj: getList())
possible?
al nik
Ranch Hand
Posts: 60
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
it's possible if for example your getList() method returns a "List of ArrayList"
public List<ArrayList> getList() { ... } ... for (ArrayList list : getList()) { ... }
but this is not your case..
[ October 21, 2007: Message edited by: al nik ]
SCJP5 - SCWCD5 - SCBCD5
It looks like it's time for me to write you a reality check! Or maybe a tiny ad!
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
sum of non numeric elements in an ArrayList
enthuware error?
Static Blocks
Linked List - inserting value to correct position
TypeCasting in Generics
More...