Home » Binary Search in Java

Binary Search in Java

by Online Tutorials Library

Binary Search in Java

Binary search is used to search a key element from multiple elements. Binary search is faster than linear search.

In case of binary search, array elements must be in ascending order. If you have unsorted array, you can sort the array using Arrays.sort(arr) method.

Binary Search Example in Java

Let’s see an example of binary search in java.

Test it Now

Output:

Element is found at index: 2 

Binary Search Example in Java using Recursion

Let’s see an example of binary search in java where we are going to search an element from an array using recursion.

Test it Now

Output:

Element is found at index: 2 

Binary Search Example in Java using Arrays.binarySearch()

Test it Now

Output:

Element is found at index: 2 
Next TopicJava Programs

You may also like