提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
在Java长数组上执行二进制搜索
/*from nowjava - 时 代 Java*/ import java.util.Arrays; public class Main { public static void main(String[] args) { long longArray[] = {1,2,4,5}; Arrays.sort(longArray); long searchValue = 2; long intResult = Arrays.binarySearch(longArray,searchValue); System.out.println("Result of binary search of 2 is : " + intResult); searchValue = 3; intResult = Arrays.binarySearch(longArray,searchValue); System.out.println("Result of binary search of 3 is : " + intResult); }/* 来 自 N o w J a v a . c o m*/ }