Binary Search on Java Float Array
Chapter:
Collections
Last Updated:
17-05-2016 18:25:46 UTC
Program:
/* ............... START ............... */
import java.util.Arrays;
public class JavaBinarySearchOnFloatArray {
public static void main(String[] args) {
//create float array
float floatArray[] = {1.23f,2.10f,4.74f,5.34f};
Arrays.sort(floatArray);
float searchValue = 4.74f;
int intResult = Arrays.binarySearch(floatArray,searchValue);
System.out.println("Result of binary search of 4.74 is : " + intResult);
searchValue = 3.33f;
intResult = Arrays.binarySearch(floatArray,searchValue);
System.out.println("Result of binary search of 3.33 is : " + intResult);
}
}
/* ............... END ............... */
Output
Result of binary search of 4.74 is : 2
Result of binary search of 3.33 is : -3
Tags
Collection, Binary Search on Java Float Array, Java