public class CollectionsDemo {
public static void main(String[] args) {
binarySearch();
}
public static void binarySearch() {
List<String> list = new ArrayList<String>();
list.add("abfn");
list.add("aaaa");
list.add("aaaa");
list.add("bhfe");
Collections.sort(list);
sop(list);
int index = Collections.binarySearch(list, "aaaa");
sop("index=" + index);
}
为什么打印aaaa的角标是1,而不是0呢? |
|