62,628
社区成员
发帖
与我相关
我的任务
分享

public class ArraysDemo {
public static void main(String[] args) {
function1();
}
/*
* static int binarySearch(数组,被查找的元素)
* 数组的二分搜索法
* 返回元素在数组中出现的索引
* 元素不存在,返回的是-(插入点-1)
*/
public static void function1() {
int[] arr = {45,45,45,21,45,22,54};
int index = Arrays.binarySearch(arr,45);
System.out.println(index);
}
}