java基础之对象数组

时间:2022-04-18 11:31:58

1 数组复制的4种方式

1.1 利用for循环

int[] a = {1,2,4,6};
int length = a.length;
int[] b = new int[length];
for (int i = 0; i < length; i++) {
b[i] = a[i];
}

1.2 直接赋值

int[] array1 = {1,2,4,6};
int[] array2 = array1;

1.3 利用Arrays自带的copyof

int copy[] = Arrays.copyOf(a, a.length);

1.4 System.arraycopy

2 例子

定义格式:student[] students = new student[i];
java基础之对象数组