方法一:
package com.lsh;
public class ExpTst {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] numbers={1,2,3};
int[] temp=new int[6];
int len=numbers.length;
for (int i = 0; i < len; i++) {
temp[i]=numbers[i];
}
numbers=temp;
for (int i : temp) {
System.out.print(i+" ");
}
System.out.println();
}
}
运行结果:1 2 3 0 0 0
方法二:
使用java.util.Arrays类的copyOf方法
int[] numbers={1,2,3}'
int[] newArray=Arrays.copyOf(numbers,6);
与copyOf类似的还有一个copyOfRange方法
标签:copyOf,temp,int,System,修改,numbers,数组,扩充,out From: https://blog.51cto.com/u_15847885/5798128