obtaining an int[] from Collection<Integer> ?

Discussion in 'Java' started by Andreas Leitgeb, Oct 20, 2008.

  1. Is there any standard-library method, that would take an
    Integer[] or Collection<Integer>, and give me an int[] ?
    I'd need the int[] for some external interface.

    If "do it yourself" is the only answer, then there's no
    need to elaborate on that. I do know how to do it myself.
    I just wouldn't want to reinvent a wheel.

    PS:
    It would, of course, generally have to deal with
    null-values, but not in my case: it's a null-free
    Collection.
    Andreas Leitgeb, Oct 20, 2008
    #1
    1. Advertising

  2. Andreas Leitgeb

    Sigfried Guest

    Andreas Leitgeb a écrit :
    > Is there any standard-library method, that would take an
    > Integer[] or Collection<Integer>, and give me an int[] ?
    > I'd need the int[] for some external interface.


    not in jdk1.5

    > If "do it yourself" is the only answer, then there's no
    > need to elaborate on that. I do know how to do it myself.
    > I just wouldn't want to reinvent a wheel.
    >
    > PS:
    > It would, of course, generally have to deal with
    > null-values, but not in my case: it's a null-free
    > Collection.
    Sigfried, Oct 20, 2008
    #2
    1. Advertising

  3. Andrea Francia <_FROM_HERE_ohohohioquestoèdatogliereohohoho_TO_HERE.it> wrote:
    > Andreas Leitgeb wrote:
    >> Is there any standard-library method, that would take an
    >> Integer[] or Collection<Integer>, and give me an int[] ?
    >> I'd need the int[] for some external interface.

    > I don't know. Maybe this library could help:
    > http://commons.apache.org/primitives/


    Thanks.
    It helped me indirectly: The idea of using special
    Collections of primitives, made me look again at
    BitSet, and this time I found it suitable for my job.

    I still have to construct the int[] manually, but other
    parts of my code improved a lot by using a BitSet.
    The numbers are expected to be well below 1000 (for
    domain-specific reasons), and checking containment,
    adding and removing happens much more often than
    obtaining that array.
    Andreas Leitgeb, Oct 20, 2008
    #3
  4. Sigfried <> wrote:
    > Andreas Leitgeb a écrit :
    >> Is there any standard-library method, that would take an
    >> Integer[] or Collection<Integer>, and give me an int[] ?
    >> I'd need the int[] for some external interface.

    > not in jdk1.5


    The problem itself has dissolved, but out of curiosity:

    Does that explicit restriction to 1.5 mean:
    "I don't know for other versions"
    or does it mean:
    "starting with 1.6 there is ..."
    ? :)
    Andreas Leitgeb, Oct 20, 2008
    #4
  5. Andreas Leitgeb

    Sigfried Guest

    Andreas Leitgeb a écrit :
    > Sigfried <> wrote:
    >> Andreas Leitgeb a écrit :
    >>> Is there any standard-library method, that would take an
    >>> Integer[] or Collection<Integer>, and give me an int[] ?
    >>> I'd need the int[] for some external interface.

    >> not in jdk1.5

    >
    > The problem itself has dissolved, but out of curiosity:
    >
    > Does that explicit restriction to 1.5 mean:
    > "I don't know for other versions"
    > or does it mean:
    > "starting with 1.6 there is ..."


    "I don't know for other versions" :)
    Sigfried, Oct 20, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Schnoffos
    Replies:
    2
    Views:
    1,208
    Martien Verbruggen
    Jun 27, 2003
  2. Hal Styli
    Replies:
    14
    Views:
    1,629
    Old Wolf
    Jan 20, 2004
  3. Peter Kwan
    Replies:
    2
    Views:
    672
  4. Robben
    Replies:
    14
    Views:
    560
    Old Wolf
    Dec 27, 2005
  5. Øyvind Isaksen
    Replies:
    1
    Views:
    964
    Øyvind Isaksen
    May 18, 2007
Loading...

Share This Page