int[] arr = new int[]{ 3,6,8,9 };
System.out.println(arr.length);
int len = arr . length ;
System.out.println("数组长度为:" + len);
/*System.arraycopy方法用于数组复制
*public static void arraycopy (Object src, int srcPos,Object dest, int destPos, int length)
src:源数组 srcPos:源数组中的起始位置 dest:目标数组 destPos : 目标数组中的起始位置 length:要复制的数组元素的数量
int[ ] a = { 10 ,20 ,30 ,40 ,50 };
int[ ] a1 = new int[ 6 ] ;
System.arraycopy( a , 1 , a1 , 0 , 4 );
结果:20,30,40,50
排序:
冒泡排序:
int[] arr = {89,50,84,57,61,20,86};
for(int i=0;i<arr.length-1;i++){ f
or(int j=0;j<arr.length-1-i;j++){
if(arr[j]>arr[j+1]){
int temp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = temp;
}
}
}
Arrays.sort方法用于数组排序:
int[ ] arr = { 49, 81, 1, 64, 77, 50, 0, 54, 77, 18 };
Arrays.sort( arr ) ;
for(int i=0; i<arr.length; i++) {
System.out.println(arr[i] ); }
Arrays.copyOf方法用于数组复制:
类型[ ] newArray = Arrays.copyOf ( 类型[ ] original , int newLength )
int [ ] a = { 10,20,30,40,50 } ;
int [ ] a1 = Arrays . copyOf ( a, 6 );
数组的“扩容”:
int [ ] a = { 10,20,30,40,50 } ;
a = Arrays . copyOf ( a, a.length+1 );
}
}