Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.Arrays;

public class Main {

    public static void main(String[] args) {

        // initializing sorted array
        Object arr[] = { 1, 2, 22, 69, 111, 222 };

        // value to search
        int searchVal = 22;

        // entering range of index
        int retVal = Arrays.binarySearch(arr, 2, 4, searchVal);

        System.out.println("The index of element 22 is : " + retVal);
    }
}