Online Java Compiler By
JavaTpoint.com
import java.util.Arrays; class BinarySearchExample2{ public static void main(String args[]){ int arr[] = {10,20,30,40,50}; int key = 30; int result = Arrays.binarySearch(arr,key); if (result < 0) System.out.println("Element is not found!"); else System.out.println("Element is found at index: "+result); } }
Output