我有一个int
数组:
int[] arr = {1,2,3,4,5};
如何将此数组转换为Integer
数组,例如:
Integer[] array = {1,2,3,4,5};
答案 0 :(得分:1)
尝试,
int[] oldArray = {1,2,3,4,5};
Integer[] newArray = new Integer[oldArray.length];
int i = 0;
for (int value : oldArray) {
newArray[i++] = Integer.valueOf(value);
}
答案 1 :(得分:0)
int[] old = {1,2,3,4,5};
Integer[] arr = new Integer[old.length];
System.arraycopy(old, 0, arr, 0, old.length);
或者您可以使用Apache commons-lang
Integer[] arr = ArrayUtils.toObject(old);