package day4_array; import java.util.Arrays; public class ArrayBool { public static void main(String[] args) { //java.util.Arrays工具类.操作数组的工具类,包含了很多操作数组的方法 //1.boolean equals(); int arr1[]=new int[] {1,2,3,4}; int[] arr2=new int[] {1,3,2,4}; System.out.println(Arrays.equals(arr1,arr2)); //2.toString遍历输出数组 System.out.println(Arrays.toString(arr1)); //3.fill,将指定的值填到数组中,实现替换 Arrays.fill(arr1,10);//将arr1中元素全部换成10 System.out.println(Arrays.toString(arr1)); //4.sort,排序 arr1=new int[] {23,44,5,1}; Arrays.sort(arr1); System.out.println(Arrays.toString(arr1)); //5.int binarySearch(int[] a,int key)二分法查找 int[] number=new int[] {2,5,7,8,10,15,18,20,22,25,28}; int index=Arrays.binarySearch(number, 19); if(index>=0) { System.out.println("找到了"); }else System.out.println("没找到"); } }
标签:Java,--,day4,Arrays,System,int,arr1,println,out From: https://www.cnblogs.com/NGZS/p/16858548.html