Performing Binary Search on Java int Array Example
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
int intArray[] = { 1, 2, 4, 5 };
Arrays.sort(intArray);
int searchValue = 2;
System.out.println(Arrays.binarySearch(intArray, searchValue));
searchValue = 3;
System.out.println(Arrays.binarySearch(intArray, searchValue));
}
}
Related examples in the same category