Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.Arrays;
import java.util.Comparator;

public class Main {

    public static void main(String[] args) {

        // initializing sorted short array
        Short shortArr[] = new Short[] { 1, 2, 15, 52, 110 };

        // use comparator as null, sorting as natural ordering
        Comparator<Short> comp = null;

        // entering the value to be searched 
        short searchVal = 15;

        // search between index 1 and 4
        int retVal = Arrays.binarySearch(shortArr, 1, 4, searchVal, comp);
        System.out.println("The index of element 15 is : " + retVal);

    }
}