package com.atguigu.java; import java.util.Arrays; public class ArrayTest { public static void main(String[] args){ //1.boolean equals(int[] a,int[] b):判断两个数组是否相等。 int[] arr1 = {1,2,3,4,8,9,0}; int[] arr2 = {1,4,3,10,0,9,0}; String[] arr3 = {"mm","oo","ll"}; boolean isEquals = Arrays.equals(arr1,arr2); System.out.println(isEquals); //2.String toString(int[] a):输出数组信息。 System.out.println(Arrays.toString(arr1)); //3.void fill(int[] a,int val):将指定值填充到数组之中。 Arrays.fill(arr3,"oo"); System.out.println(Arrays.toString(arr3)); Arrays.fill(arr1,10); System.out.println(Arrays.toString(arr1)); //4.void sort(int[] a):对数组进行排序。 Arrays.sort(arr2); System.out.println(Arrays.toString(arr2)); //5.int binarySearch(int[] a,int key);二分检索。 int key = 1; int index = Arrays.binarySearch(arr2,key); if(index >= 0){ System.out.println(index); }else{ System.out.println("找不到"); } } }
原文:https://www.cnblogs.com/yzyjava/p/14354182.html