Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2012
    Rep Power

    Default 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.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power

    Default 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,

    Last edited by JosAH; 06-16-2012 at 09:24 AM.
    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. Replies: 1
    Last Post: 10-16-2011, 10:58 AM
  2. How to convert array of Objects into array of Strings
    By elenora in forum Advanced Java
    Replies: 1
    Last Post: 06-10-2011, 04:48 PM
  3. Replies: 1
    Last Post: 04-19-2011, 05:32 PM
  4. convert unsigned integer to signed integer in java?
    By diskhub in forum New To Java
    Replies: 6
    Last Post: 05-17-2010, 01:50 AM
  5. How to convert List to Array
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-16-2008, 11:37 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts