二分法binadySearch的用法

package com.Summer_0420.cn;

import java.util.Arrays;

/**
 * @author Summer
 * 二分法binadySearch的用法(测试)
 */
public class TestMethod04 {
    public static void main(String[] args) {
        int [] a = {1,2,3,4,5,6,7,8,9,10};
        int index = Arrays.binarySearch(a, 2);
        System.out.println(index);//输出1
        int index1 = Arrays.binarySearch(a, 11);
        System.out.println(index1);//输出-11
        a = null; 
        int index2 = Arrays.binarySearch(a, 3);
        System.out.println(index2);//输出空指针异常java.lang.NullPointerException
    }

}

 

posted @ 2019-04-20 22:29  Geek张东坡  阅读(302)  评论(0编辑  收藏  举报