Binary Search on Java Short Array
Chapter:
Collections
Last Updated:
17-05-2016 18:31:55 UTC
Program:
/* ............... START ............... */
import java.util.Arrays;
public class JavaBinarySearchOnShortArray {
public static void main(String[] args) {
// create short array
short shortArray[] = { 1, 2, 4, 5 };
Arrays.sort(shortArray);
short searchValue = 2;
int intResult = Arrays.binarySearch(shortArray, searchValue);
System.out.println("Result of binary search of 2 is : " + intResult);
searchValue = 3;
intResult = Arrays.binarySearch(shortArray, searchValue);
System.out.println("Result of binary search of 3 is : " + intResult);
}
}
/* ............... END ............... */
Output
Result of binary search of 2 is : 1
Result of binary search of 3 is : -3
Tags
Collection, Binary Search on Java Short Array, Java