logoNEURAL COOK
SearchAll PostsTagsNotesAuthor
logoNEURAL COOK

A posts created with Next.js and Tailwind.css

Explore

  • All posts
  • Notes
  • Snippets
  • Tags
  • RSS feed

Connect

instagramtwitterfacebookyoutubelinkedinmailgithub

© 2026 VIKI. All rights reserved.

Built with
Contents
ArraysData StructuresListMath OperationBinary SearchSortingString Operation
Snippets/java

Binary Search

1 min read
On this pageArrays
ArraysExample

# 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 OperationNext→Sorting

On this page

ArraysExample