About 705,000 results
Open links in new tab
  1. Find a String in given Array of Strings using Binary Search

    Apr 9, 2025 · Given a sorted array of Strings arr and a string x, The task is to find the index of x in the array using the Binary Search algorithm. If x is not present, return -1. Examples: Input: arr[] = {“contribute”, “geeks”, “ide”, “practice”}, x = “ide” Output: …

  2. Binary Search in Java - GeeksforGeeks

    Apr 11, 2025 · Binary search is a highly efficient searching algorithm used when the input is sorted. It works by repeatedly dividing the search range in half, reducing the number of comparisons needed compared to a linear search.

  3. Implementing binary search on an array of Strings

    Aug 27, 2015 · public static int binarySearch(String[] a, String x) { int low = 0; int high = a.length - 1; int mid; while (low <= high) { mid = (low + high) / 2; if (a[mid].compareTo(x) < 0) { low = mid + 1; } else if (a[mid].compareTo(x) > 0) { high = mid - 1; } else { return mid; } } return -1; } public static void main(String[] args) { Scanner input = new ...

  4. Collections.binarySearch() in Java with Examples

    Mar 11, 2025 · java.util.Collections.binarySearch () method is a java.util.Collections class method that returns the position of an object in a sorted list. If the key is not present, Then it returns “ (- (insertion point) – 1)”. would be inserted into the list.

  5. Binary Search Algorithm in Java - Baeldung

    Jun 6, 2024 · This tutorial demonstrated a binary search algorithm implementation and a scenario where it would be preferable to use it instead of a linear search. The code backing this article is available on GitHub.

  6. Java Program to Implement Binary Search Algorithm

    Here, we have used the Java Scanner Class to take input from the user. Based on the input from user, we used the binary search to check if the element is present in the array. We can also use the recursive call to perform the same task.

  7. Java String Binary Search Example - onlinetutorialspoint

    Jun 17, 2018 · Here we are going to find a specific element in a string array using Binary Search Algorithm. Searching a string using binary search algorithm is something tricky when compared to searching a number. Because we can compare 2 numerics directly, but in the case of strings it’s not as simple as number comparison.

  8. How to Use Arrays.binarySearch() in Java - freeCodeCamp.org

    Aug 23, 2022 · In this article, I'm going to show you how to use the Arrays.binarySearch() method in Java. What is Arrays.binarySearch() in Java? According to the official docs on the Arrays.binarySearch() method: (It) Searches the specified array of bytes for the specified value using the binary search algorithm.

  9. Binary Search in Java - Know Program

    Binary Search in Java | Binary search is an efficient algorithm for finding an item from a sorted list or array of items. Sometimes it is also known as half-interval search, logarithmic search, or binary chop. Condition to use the binary search:- The array must be sorted in ascending order.

  10. Mastering Binary Search in Java – A Comprehensive Tutorial

    Nov 3, 2024 · In this comprehensive Java tutorial, you‘ll not only learn how to implement binary search, but also truly master when, why, and how to leverage its O(log n) efficency in real-world code. Practical Binary Search Use Cases

  11. Some results have been removed
Refresh