Arrays.binarySearch(long[] a, int fromIndex, int toIndex, long key) has the following syntax.
public static int binarySearch(long[] a, int fromIndex, int toIndex, long key)
In the following code shows how to use Arrays.binarySearch(long[] a, int fromIndex, int toIndex, long key) method.
Binary search needs sorted arrays.
/* w w w .java 2 s .c o m*/ import java.util.Arrays; public class Main { public static void main(String[] args) { // initializing sorted long array long longArr[] = {123456789L,1123456789L,2123456789L,3123456789L,4123456789L}; // value to search long searchVal = 2123456789L; int retVal = Arrays.binarySearch(longArr,searchVal); System.out.println(retVal); } }
The code above generates the following result.