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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
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
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

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://aspose.com/file-tools
 
subject: converting int array to List