toString

对数组进行遍历查看的

  1. //给定一个数组:
  2. int[] arr = {1, 3, 7, 2, 4, 8};
  3. //toString:对数组进行遍历查看的,返回的是一个字符串,这个字符串比较好看
  4. System.out.println(Arrays.toString(arr));

image.png


binarySearch

二分法查找:找出指定数组中的指定元素对应的索引

  1. int[] arr = {1, 3, 7, 2, 4, 8};
  2. Arrays.sort(arr);
  3. System.out.println(Arrays.toString(arr));
  4. System.out.println(Arrays.binarySearch(arr, 4));

image.png


sort

排序 —>升序

  1. int[] arr = {1, 3, 7, 2, 4, 8};
  2. Arrays.sort(arr);
  3. System.out.println(Arrays.toString(arr));

image.png


copyOf

完成数组的复制

  1. int[] arr2 = {1, 3, 7, 2, 4, 8};
  2. //copyOf:完成数组的复制:
  3. int[] newArr = Arrays.copyOf(arr2, 4);
  4. System.out.println(Arrays.toString(newArr));

image.png


copyOfRange

区间复制

  1. int[] newArr2 = Arrays.copyOfRange(arr2, 1, 4);//[1,4)-->1,2,3位置
  2. System.out.println(Arrays.toString(newArr2));

image.png


equals

比较两个数组的值是否一样

  1. int[] arr3 = {1, 3, 7, 2, 4, 8};
  2. int[] arr4 = {1, 3, 7, 2, 4, 8};
  3. System.out.println(Arrays.equals(arr3, arr4));//true
  4. System.out.println(arr3 == arr4);
  5. //false ==比较左右两侧的值是否相等,比较的是左右的地址值,返回结果一定是false

image.png


fill

数组的填充

  1. int[] arr5 = {1, 3, 7, 2, 4, 8};
  2. Arrays.fill(arr5, 10);
  3. System.out.println(Arrays.toString(arr5));

image.png