logoNEURAL COOK
SearchAll PostsTagsNotesAuthor
instagramtwitterfacebookyoutubelinkedinmailgithubrss
Copyright © 2026 All rights reserved.
•
VIKI
Built with Vikramaditya Singh
Built with
VIKI - A posts created with Next.js and Tailwind.css
java
Arrays
Data Structures
List
Math Operation
Binary Search
Sorting
String Operation
Snippets›java

Binary Search

# Arrays

public static T binarySearch(T[] a,int fromIndex,int toIndex,T key)

Searches a range of the specified array for the specified value it return index of the search key, if it is contained in the array within the specified range. Otherwise, , where the insertion point is defined as the point at which the key would be inserted into the array.

# Example

to search for the index of target in a sorted array nums using binary search.

int index = Arrays.binarySearch(nums,target);
to interpret the result
if (index >= 0) {
    // target found at index
} else {
    int insertionPoint = -index - 1;
    // target not found, but would go at insertionPoint to keep array sorted
}
PreviousMath OperationNextSorting
CONTENTS
ArraysExample