Javatpoint Logo
Javatpoint Logo

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


Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA