Performing Binary Search on Java long Array - Java Language Basics

Java examples for Language Basics:long

Description

Performing Binary Search on Java long Array

Demo Code


import java.util.Arrays;
 
public class Main {
  public static void main(String[] args) {
    long longArray[] = {1,2,4,5};
    Arrays.sort(longArray);/*  w  w  w  . java 2  s  . c  o m*/
   
    long searchValue = 2;
   
    long intResult = Arrays.binarySearch(longArray,searchValue);
    System.out.println("Result of binary search of 2 is : " + intResult);
   
    searchValue = 3;
    intResult = Arrays.binarySearch(longArray,searchValue);
    System.out.println("Result of binary search of 3 is : " + intResult);
 
  }
}

Result


Related Tutorials