//fill()方法:将value值,赋给整个数组的每个元素;
int value = 0;
fill(arr2, value);
// System.out.println("fill()方法,将value值,赋给整个数组的每个元素");
System.out.print("新数组:");
for (int i = 0; i < arr2.length; i++) {
System.out.print(arr2[i]+" ");
}
System.out.println();
System.out.println("-----------------------------------------");
//fill()方法:从索引值fromIndex到toIndex,包括fromIndex,不包括toIndex,将value值,赋进去;
int fromIndex = 2;
int toIndex = 3;
fill(arr3, fromIndex, toIndex, value);
// System.out.println("fill()方法,从索引值fromIndex到toIndex,包括fromIndex,不包括toIndex,将value值,赋进去");
System.out.print("新数组:");
for (int i = 0; i < arr3.length; i++) {
System.out.print(arr3[i]+" ");
}
System.out.println();
System.out.println("-----------------------------------------");
//方法copyOf(),功能:将数组arr中的newLength个元素拷贝到新数组中,并将新数组返回,从索引为0开始
int newLength = 4;
// copyOf(arr4, newLength);
int[] newArr1 = copyOf(arr4, newLength);
System.out.print("新数组:");
for (int i = 0; i < newArr1.length; i++) {
System.out.print(newArr1[i]+" ");
}
System.out.println();
System.out.println("-----------------------------------------");
int from = 3;
int to = 6;
int[] newArr2 = copyOfRange(arr5, from, to);
// System.out.println("将数组arr中从索引from(包含from)开始到索引to结束(不包含to)的元素复制到新数组中,并将新数组返回");
System.out.print("新数组:");
for (int i = 0; i < newArr2.length; i++) {
System.out.print(newArr2[i]+" ");
}
System.out.println();
System.out.println("-----------------------------------------");
}
public static boolean equals(int[] arr1,int[] arr2){
return Arrays.equals(arr1, arr2);
}
public static void fill(int[] arr,int value){
for (int i = 0; i < arr.length; i++) {
arr[i]=value;
}
}
public static void fill(int[] arr,int fromIndex,int toIndex,int value){
for (int i = fromIndex; i < toIndex; i++) {
arr[i] = value;
}
}
public static int[] copyOf(int[] arr, int newLength) {
int[] newArr1 = new int[newLength];
for (int i = 0; i < newLength; i++) {
newArr1[i]=arr[i];
}
return newArr1;
}
public static int[] copyOfRange(int[] arr,int from, int to){
int length = to - from ;
int[] newArr = new int[length];
int j = 0;
for (int i = from; i < to; i++) {
newArr[j]=arr[i];
j++;
}
return newArr;
}
}