数组的扩容问题

 1 /*
 2         数组扩容(复制)---数组长度不变
 3 
 4         System.arraycopy(源数组,源数组开始下标,新数组,新数组开始的下标,复制数组元素的个数);
 5 
 6 
 7 */
 8 import java.util.Arrays;
 9 class KuoRong{
10     public static void main(String[] args){
11         //源数组
12         int[] arr={1,2,3,4,5};
13         System.out.println(arr);
14         /*//新数组
15         int[] arr1=new int[6];
16 
17         //1.数组的复制
18         System.arraycopy(arr,0,arr1,0,5);
19 
20         //数组地址的赋值
21         arr=arr1;*/
22 
23         //2.(要操作的数组,数组长度大小)
24         //数组的扩容,缩容
25         arr=Arrays.copyOf(arr,2);
26 
27         System.out.println(arr);
28 
29         //
30         System.out.println(Arrays.toString(arr));
31     }
32 }
原文地址:https://www.cnblogs.com/nanlinghan/p/9614052.html