Java HashSet<Integer> to int array

Posted by jackweeden on Stack Overflow See other posts from Stack Overflow or by jackweeden
Published on 2010-03-15T23:27:01Z Indexed on 2010/03/15 23:29 UTC
Read the original article Hit count: 470

Filed under:
|
|
|
|

I've got a HashSet with a bunch of (you guessed it) integers in it. I want to turn it into an array, but calling

hashset.toArray();

returns an array of Object type. This is fine, but is there a better way to cast it to an array of int, other than iterating through every element manually? A method I want to pass it to

void doSomething(int[] arr)

Won't accept the Object[] array, even if I try casting it like

doSomething((int[]) hashSet.toArray());

© Stack Overflow or respective owner

Related posts about java

Related posts about hashset