JDK 1.5  代码如下 :import java.util.*;
public class test {
public static void main(String[] args) {
int[] x = new int[]{22,12,1,235,6,7,8};
Arrays.sort(x);
System.out.println(Arrays.binarySearch(x,0,3,1));

}
}错误信息:
test.java:6: 找不到符号
符号:  方法 binarySearch(int[],int,int,int)
位置:  类 java.util.Arrays
           System.out.println(Arrays.binarySearch(x,0,3,2));1错误

解决方案 »

  1.   

    import java.util.Arrays;public class Test { /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    int[] x = new int[] { 22, 12, 1, 235, 6, 7, 8 };
    Arrays.sort(x);
    System.out.println(Arrays.binarySearch(x, 7)); }}上面结果返回 2,经过排序后 你要搜索的值7 排在 x 数组内的第2位,你的写法好像是多传了2个变量(x,0,3,2),你可以参考一下java api 中关于binarySearch 二分搜索法的介绍
      

  2.   

    谢谢楼上的。找到原因了,我的JDK是1.5,不支持这种搜索方法,在JDK1.6下面一切正常。