Integer[] arr = set.toArray(new Integer[set.size()]);
if you want to transfer from HashSet<Integer> to int[], you have to iterate over the set.
Otherwise you need to use apache's library.
public int[] toInt(Set<Integer> set) {
int[] a = new int[set.size()];
int i = 0;
for (Integer val : set) a[i++] = val;
return a;
}
网友评论