美文网首页
HashSet to int[]

HashSet to int[]

作者: sherrysack | 来源:发表于2018-05-17 11:08 被阅读0次

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;
}

相关文章

网友评论

      本文标题:HashSet to int[]

      本文链接:https://www.haomeiwen.com/subject/rtqbdftx.html