I have string array [1, 2, 3] and i search for all of those numbers using Arrays.binarySearch, it find 1 and 2, but with 3 it returns -1. any idea why it works that way? what is better alternative to always working search in array/collection?
+6
A:
An array must be sorted.
String []ar={"1","2","3"};
System.out.println(java.util.Arrays.binarySearch(ar,"3"));
adatapost
2009-08-31 09:28:04