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:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Programmer Certification (OCPJP)
Arrays asList() method
Saibabaa Pragada
Ranch Hand
Posts: 162
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
public class Arrays_Ask { public static void main(String[] args) { int[] intArray = { 10, 20, 30 }; List list = Arrays.asList(intArray); for (int i = 0; i < list.size(); i++) System.out.println(list.get(i));//How to print values from List ?? } }
Rob Camick
Rancher
Posts: 3324
32
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Not exactly sure what is going on but Lists are only for Objects. Not sure what happens when you try to use a primitive array.
Try the following and it works as you expect:
String[] intArray = { "10", "20", "30" };
Edit: it looks like it just returns the original array:
for (int i = 0; i < list.size(); i++) { int[] integers = (int[])list.get(i); System.out.println(integers[0]); System.out.println(integers[1]); System.out.println(integers[2]); }
Subhasis Gorai
Greenhorn
Posts: 3
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Please check this topic, hope it helps ..
https://coderanch.com/t/510492/java-programmer-SCJP/certification/Arrays-asList
I can't renounce my name. It's on all my stationery! And hinted in this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Triangle Problem
Doubt on Local Arrays
Doubt in ArrayList's toArray function
is this a proper mock question for the exam?
Cast Object to Object[]
More...