将整数列表转换为 int 数组[重复]

2024-04-09

有没有办法将整数列表转换为整数数组(不是整数)。类似于 List 到 int [] 的东西?无需循环遍历列表并手动将 intger 转换为 int。


您可以使用toArray得到一个数组Integers, ArrayUtils从 apache commons 将其转换为int[].


List<Integer> integerList = new ArrayList<Integer>();
Integer[] integerArray = integerList.toArray(new Integer[0]);
int[] intArray = ArrayUtils.toPrimitive(integerArray);

资源 :

  • 阿帕奇公共资源 -ArrayUtils.toPrimitive(Integer[]) http://commons.apache.org/lang/api-2.5/org/apache/commons/lang/ArrayUtils.html#toPrimitive(java.lang.Integer%5B%5D)
  • Apache 公共语言 http://commons.apache.org/lang/
  • Javadoc-Collection.toArray(T[]) http://download.oracle.com/javase/6/docs/api/java/util/Collection.html#toArray(T%5B%5D)

关于同一主题:

  • Java中如何将List转换为int[]? https://stackoverflow.com/questions/960431/how-to-convert-listinteger-to-int-in-java
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将整数列表转换为 int 数组[重复] 的相关文章

随机推荐