Java Array class binarySearch(long[] a, int fromIndex, int toIndex, long key) example
Array class binarySearch(long[] a, int fromIndex, int toIndex, long key) method example
Array class binarySearch(long[] a, int fromIndex, int toIndex, long key)method example. This example shows you how to use binarySearch(long[] a, int fromIndex, int toIndex, long key) method.This method Searches a range of the specified array of longs for the specified value using the binary search algorithm.
Here is the code:-
/**
* @Program that Searches a range of the specified array of longs for the
* specified value using the binary search algorithm
* binarySearch11Array.java
* Author:-RoseIndia Team
* Date:-15-May-2008
*/
import java.util.*;
public class binarySearch11Array {
public static void main(String[] args) {
//Creating a Long Array
long arr[]={1,5,7,4,7,6};
//Searching the array
int i=Arrays.binarySearch(arr,3,6,7);
//Displaying the element
System.out.println("The element "+arr[i]+" is found at index "+i);
}
} |
Output of the program:-
| The element 7 is found at index 4 |
|