obtaining an int[] from Collection<Integer> ?

A

Andreas Leitgeb

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

Sigfried

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
 
A

Andreas Leitgeb

Andrea Francia said:
Andreas said:
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.
 
A

Andreas Leitgeb

Sigfried said:
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 ..."
? :)
 
S

Sigfried

Andreas Leitgeb a écrit :
Sigfried said:
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" :)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top