aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes converting int array to List Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "converting int array to List" Watch "converting int array to List" New topic
Author

converting int array to List

Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

How can I do that?


Of course that doesn't work properly, because: asList(T... a), and int is not T.


SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
Ankit Garg
Saloon Keeper

Joined: Aug 03, 2008
Posts: 9189
    
    2

List cannot contains primitive elements. I think the only option is to iterate over the array and add elements to the list...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
This will work...



JDBCSupport - An easy to use, light-weight JDBC framework -
Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

OK, I knew that. So there is no way to convert int[] to list of Integers in one step.

By the way I have another question about generics.
How does compiler know that:

is:


Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
Check the implementation of the Arrays.asList class. Pretty straight forward.

 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: converting int array to List
 
Similar Threads
where can find the example answer for part3
2D Arrays
Manipulations with arrays!
generating a Product Activation Code
Threads Completed Notification