1.常用方法
方法 | 描述 |
---|---|
boolean equals(int[] a,int[] b) | 判断两个数组是否相等,顺序不一样也返回false |
String toString(int[] a) | 输出数组信息 |
void fill(int[] a,int val) | 将指定值填充到数组中(替换) |
void sort(int[] a) | 对数组进行排序 |
int binarySearch(int[] a,int key) | 对排序后的数组进行二分检索指定的值,输入未排序的数组不报错,但返回的索引有误 |
2.示例
int[] arr1 = new int[]{1,2,3,4};
int[] arr2 = new int[]{1,3,2,4};
boolean isEquals = Arrays.equals(arr1, arr2);
System.out.println(isEquals); //false
System.out.println(Arrays.toString(arr1)); //[1, 2, 3, 4]
Arrays.fill(arr1,10);
System.out.println(Arrays.toString(arr1)); //[10, 10, 10, 10]
Arrays.sort(arr2);
System.out.println(Arrays.toString(arr2)); //[1, 2, 3, 4]
int[] arr3 = new int[]{-98,-34,2,34,54,66,79,105,210,333};
int index = Arrays.binarySearch(arr3, 210);
if (index>0){
System.out.println("索引为:"+index); //索引为:8
}else {
System.out.println("没找到");
}
标签:Java,Arrays,System,int,数组,println,out
From: https://www.cnblogs.com/zhishu/p/16617502.html