zoukankan      html  css  js  c++  java
  • 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
    
  • 相关阅读:
    使用Chrome开发者工具研究JavaScript的垃圾回收机制
    Java JDK目录下的jmap和jhat工具的使用方式
    Java注解@Cacheable的工作原理
    使用Java JUnit框架里的@Rule注解的用法举例
    使用Java JUnit框架里的@SuiteClasses注解管理测试用例
    Java JUnit框架里@Category注解的工作原理
    使用SAP CRM mock框架进行单元测试的设计
    将ABAP透明表的定义(元数据)解析出来导入到剪切板(clipboard)里
    SAP ABAP Netweaver里的胖接口(fat interface)
    关于STM32的FLASH操作【转载】
  • 原文地址:https://www.cnblogs.com/sweetorangezzz/p/12918617.html
Copyright © 2011-2022 走看看