import java.util.Arrays;
public class Arrays_Study {
public static void main(String[] args) {
int a[] = new int[]{12, 122, 332, 43, 445, 65, 7, 87, 98, 6};
Arrays_Study.printArr(a);
System.out.println("");
Arrays.sort(a);
Arrays_Study.printArr(a);
System.out.println(Arrays.binarySearch(a, 445));
int[] ints = Arrays.copyOf(a, 20);
Arrays_Study.printArr(ints);
Arrays.fill(ints,888);
Arrays_Study.printArr(ints);
boolean equals = Arrays.equals(a, ints);
System.out.println(equals);
int a1[] = new int[]{12, 122, 332, 43, 445, 65, 7, 87, 98, 6};
System.out.println(Arrays.equals(a1, a));
}
public static void printArr(int a[]) {
for (int i = 0; i < a.length; i++) {
System.out.print(a[i] + " ");
}
System.out.println("");
}
}
注意点:
1.对于Arrays里面的二分查找一定要先进行排序,然后再进行查找
2.Arrays.equals()比较的是数组里面的值是否相等,比较的不是地址,new出来的对象值要是相等的照样还是true。
public class Arrays_Study {
public static void main(String[] args) {
int a[] = new int[]{12, 122, 332, 43, 445, 65, 7, 87, 98, 6};
int a1[] = new int[]{12, 122, 332, 43, 445, 65, 7, 87, 98, 6};
System.out.println(Arrays.equals(a1, a));
}
}
标签:Arrays,Study,System,equals,int,使用,工具,out From: https://blog.51cto.com/u_15738297/6140254