Java Arrays 二分查找 Long


Java Arrays 二分查找 Long

package com.codingdict;

import java.util.Arrays;

public class ArrayDemo {
   public static void main(String[] args) {

      // initializing unsorted long array
      long longArr[] = {56,46464,3342,232,3445};

      // sorting array
      Arrays.sort(longArr);

      // let us print all the elements available in list
      System.out.println("The sorted long array is:");
      for (long number : longArr) {
         System.out.println("Number = " + number);
      }

      // entering the value to be searched
      long searchVal = 232;

      int retVal = Arrays.binarySearch(longArr,searchVal);

      System.out.println("The index of element 232 is : " + retVal);
   }
}