0%

java数组的复制与填充

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public static void main(String[] args) {
/*==================复制======================*/
//克隆
int[] a = {1,2,3,4};
// int[] copyA = a.clone();
//
// int[] copyA = Arrays.copyOf(a, 4);
//
// int[] copyA = Arrays.copyOfRange(a, 1, 4);
//
// //a数组的0开始复制到copyA的1开始,复制长度3
// int[] copyA = new int[4];
// System.arraycopy(a, 0, copyA, 1, 3);
// System.out.println(Arrays.toString(copyA));

/*==================填充======================*/
Arrays.fill(a, 100);
System.out.println(Arrays.toString(a));

Arrays.fill(a, 1,3,99);
System.out.println(Arrays.toString(a));
}
------------- Thank you for reading -------------

Title - Artist
0:00