1 //操作数组的工具类 java.util.Arrays :操作数组的工具类 里面定义了很多操作数组的方法 2 public static void main(String[] args) 3 { 4 5 //1.boolean equals(int [] a,int[] b) 判断两个数组是否相等 6 int[] arr1 = new int[] {1,35,64,41,-52,1,2,5}; 7 int[] arr2 = new int[] {1,35,64,41,-52,1,5,2}; 8 boolean isEquals = Arrays.equals(arr1, arr2); 9 System.out.println(isEquals); //false元素一样 数组不一样 10 11 12 13 //2.String toString(int[] a) 输出数组信息 14 System.out.println(Arrays.toString(arr1)); 15 16 17 //3.void fill(int[] a,int val) 将指定值填充到数组之中 18 Arrays.fill(arr1,4444); 19 System.out.println(Arrays.toString(arr1)); //填充 44444 20 21 22 //4.void sort(int[] a) 对数组进行排序 23 System.out.println(Arrays.toString(arr2)); 24 Arrays.sort(arr2); 25 System.out.println(Arrays.toString(arr2)); 26 27 28 29 //5.int binarySerach(int[] a,int key) 对排序后的数组进行二分法检索指定的值 30 //有序 //负数没有找到 31 int [] arr3 = new int[] {21,25,35,54,65,85,97,98,99,321}; 32 int index = Arrays.binarySearch(arr3, 321); 33 if(index >=0) 34 { 35 System.out.println("找到了,它在第"+index+"位."); 36 } 37 else 38 { 39 System.out.println("没有找到!"); 40 } 41 42 43 44 } 45