且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

铸造包装的ArrayList的相应基元数组

更新时间:2023-02-27 08:11:03

Apache的百科全书/郎有一个类ArrayUtils定义这些方法。


  • 所有调用的方法 toObject()由原始数组转换为包装器阵列。

  • 所有名为 toPrimitive()从包装对象数组基本数组转换

我想,你需要ArrayUtils's$c$c> toPrimitive()$c$c>

 公共静态短[] toPrimitive(短[]数组)


  

对象短裤的数组转换为基元。


块引用>

I use an ArrayList with the wrapper class Short.
After adding some values I want to get the primitive array, but it seems that there is no way with the function toArray(Object[] array), because it need an Array with the wrapper class.

Is there another way without using a for or anything like that?

Apache Commons / Lang has a class ArrayUtils that defines these methods.

  • All methods called toObject() convert from primitive array to wrapper array.
  • All called toPrimitive() convert from wrapper object array to primitive array

I think, you need ArrayUtils's toPrimitive()

public static short[] toPrimitive(Short[] array)

Converts an array of object Shorts to primitives.