//定义并初始化一维数组3种方法
int[] arr={1,2,3,4,5}; //1
int[] arr=new int[5]; //2
int[] arr=new int[]{1,2,3,4,5}; //3
int[] arr2=arr.clone(); //1
int[] arr2=Arrays.copyOf(arr,arr.length); //2
int[] arr2=new int(arr.length); //3
System.arrcopy(arr2,0,arr,0,arr.legth);
//定义并初始化二维数组3种方法
int[][] arr1=new int[][]{1,2,3}{4,5,6}; //1
int[][] arr1=new int[3][2]; //2
int[][] arr1[]=new int[3][]; //3
arr1[0]=new int[]{1,2,3};
arr1[1]=new int[]{4,5,6};
arr1[2]=new int[]{7,8,9};
//克隆一个二维数组
for (int i=0;i<arr1.length;i++);
{
int[i] arr3=arr1.clone();
}
Arrays.sort(arr);
System.out.println(Arrays.toString(arr));
Arrays.fill(arr,-1);
//foreach语句
for(int[] arr1:arr4)
for(int val:arr1)
{
System.out.println(val+"");
}
System.out.println();
}
//
public static int sum(int... args){
sum=0;
for(int val:sum){
sum+=val;
}
return 0;
}
sum={1,2};
sum={1,2,3,4}
int[] arr={1,2,3,4,5}; //1
int[] arr=new int[5]; //2
int[] arr=new int[]{1,2,3,4,5}; //3
int[] arr2=arr.clone(); //1
int[] arr2=Arrays.copyOf(arr,arr.length); //2
int[] arr2=new int(arr.length); //3
System.arrcopy(arr2,0,arr,0,arr.legth);
//定义并初始化二维数组3种方法
int[][] arr1=new int[][]{1,2,3}{4,5,6}; //1
int[][] arr1=new int[3][2]; //2
int[][] arr1[]=new int[3][]; //3
arr1[0]=new int[]{1,2,3};
arr1[1]=new int[]{4,5,6};
arr1[2]=new int[]{7,8,9};
//克隆一个二维数组
for (int i=0;i<arr1.length;i++);
{
int[i] arr3=arr1.clone();
}
Arrays.sort(arr);
System.out.println(Arrays.toString(arr));
Arrays.fill(arr,-1);
//foreach语句
for(int[] arr1:arr4)
for(int val:arr1)
{
System.out.println(val+"");
}
System.out.println();
}
//
public static int sum(int... args){
sum=0;
for(int val:sum){
sum+=val;
}
return 0;
}
sum={1,2};
sum={1,2,3,4}