I've got a HashSet<Integer>
with a bunch of Integers
in it. I want to turn it into an array, but calling
hashset.toArray();
returns an Object[]
. Is there a better way to cast it to an array of int
other than iterating through every element manually? I want to pass the array to
void doSomething(int[] arr)
which won't accept the Object[] array, even if I try casting it like
doSomething((int[]) hashSet.toArray());
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…