Results 1 to 2 of 2
- 06-16-2012, 07:35 AM #1
Member
- Join Date
- Jun 2012
- Posts
- 6
- Rep Power
- 0
Convert List of Integer Objects to primitive int array
Hi Experts,
I have started learning java recently and looking into some practice exercise. Just wante to know if there is a easy way, to convert a List of java.lang.Integer objects to array of primitive int type (not integer).
Something like List<Integer> to int []? Or I need to loop through each element in list and convert it?
Please let me know.
Please feel free to move this thread to right location just in case I have posted this in the wrong place. Thanks in advance.
- 06-16-2012, 08:07 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
Re: Convert List of Integer Objects to primitive int array
Arrays always have been a bit of a burden; they are quite handy for primitive type of programminng but they don't work well in a more OO type of world; i.e. they can't have generic types and are quite dumb compared to the Collections framework. the Arrays and Collections utility classes try to close the gap but when it comes to arrays of primitives you have to do the nitty-gritty work yourself: loop over the List and convert each element and store them in your destination array.
kind regards,
JosLast edited by JosAH; 06-16-2012 at 08:24 AM.
When people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
How to create an array of objects which has integer field
By shaztech in forum New To JavaReplies: 1Last Post: 10-16-2011, 09:58 AM -
How to convert array of Objects into array of Strings
By elenora in forum Advanced JavaReplies: 1Last Post: 06-10-2011, 03:48 PM -
What is the difference between Integer class and int primitive data type?
By rajkobie in forum New To JavaReplies: 1Last Post: 04-19-2011, 04:32 PM -
convert unsigned integer to signed integer in java?
By diskhub in forum New To JavaReplies: 6Last Post: 05-17-2010, 12:50 AM -
How to convert List to Array
By Java Tip in forum java.langReplies: 0Last Post: 04-16-2008, 10:37 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks