Convert List of Integer Objects to primitive int array
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.
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.