• java.util.Arrays.binarySearch方法


    java.util.Arrays.binarySearch方法

    Modifier and Type 方法 描述
    static int binarySearch(byte[] a, byte key) 使用二进制搜索算法搜索指定值的指定字节数组。
    static int binarySearch(byte[] a, int fromIndex, int toIndex, byte key) 使用二进制搜索算法搜索指定值的指定字节数组的范围。
    static int binarySearch(char[] a, char key) 使用二进制搜索算法搜索指定数组的指定值。
    static int binarySearch(char[] a, int fromIndex, int toIndex, char key) 使用二分搜索算法搜索指定值的指定数组的范围。
    static int binarySearch(double[] a, double key) 使用二进制搜索算法搜索指定值的指定数组的双精度值。
    static int binarySearch(double[] a, int fromIndex, int toIndex, double key) 使用二分搜索算法搜索指定值的指定数组的双精度范围。
    static int binarySearch(float[] a, float key) 使用二叉搜索算法搜索指定数组的浮点数。
    static int binarySearch(float[] a, int fromIndex, int toIndex, float key) 使用二分搜索算法搜索指定数组的浮点数范围。
    static int binarySearch(int[] a, int key) 使用二叉搜索算法搜索指定的int数组的指定值。
    static int binarySearch(int[] a, int fromIndex, int toIndex, int key) 使用二叉搜索算法搜索指定值的指定数组的范围。
    static int binarySearch(long[] a, int fromIndex, int toIndex, long key) 使用二分搜索算法搜索指定值的指定数组的范围。
    static int binarySearch(long[] a, long key) 使用二进制搜索算法搜索指定数组的指定数组。
    static int binarySearch(short[] a, int fromIndex, int toIndex, short key) 使用二进制搜索算法搜索指定值的指定数组的短整型范围。
    static int binarySearch(short[] a, short key) 使用二进制搜索算法搜索指定值的指定数组的指定值。
    static int binarySearch(Object[] a, int fromIndex, int toIndex, Object key) 使用二进制搜索算法搜索指定对象的指定数组的范围。
    static int binarySearch(Object[] a, Object key) 使用二叉搜索算法搜索指定对象的指定数组。
    static int binarySearch(T[] a, int fromIndex, int toIndex, T key, Comparator c) 使用二进制搜索算法搜索指定对象的指定数组的范围。
    static int binarySearch(T[] a, T key, Comparator c) 使用二叉搜索算法搜索指定对象的指定数组。

    binarySearch(int[] a, int key)

    import java.util.Arrays;
    
    public class TestBinarySearch {
        public static void main(String[] args) {
            test();
    
        }
        //测试  binarySearch()方法
        public static void test(){
            int[] a = {1,2,3,5,10,8};
            Arrays.sort(a);
            System.out.println("排序后的数组为:"+Arrays.toString(a));
            int index = Arrays.binarySearch(a, 5);
            System.out.println("5在排序后数组的位置为:"+index);
    
        }
    }
    
    
    排序后的数组为:[1, 2, 3, 5, 8, 10]
    5在排序后数组的位置为:3
    
  • 相关阅读:
    SQL Server游标的使用
    SQL函数说明大全
    基本数据结构:链表(list)
    QT+C++实现连连看
    printf按8进制、16进制输出
    关于数据库优化问题收集
    SQL Server 查询处理中的各个阶段(SQL执行顺序) 转
    MFC消息机制
    _T() 和_L() _TEXT __T,L区别与联系详解
    Windows 各种控件使用心得
  • 原文地址:https://www.cnblogs.com/sweetorangezzz/p/12918617.html
Copyright © 2020-2023  润新知