package com.logicbig.example.collections;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class BinarySearchExample {
public static void main(String... args) {
List<String> list =
Arrays.asList("one", "two", "three", "four");
Collections.sort(list);
System.out.println("sorted list: " + list);
int index = Collections.binarySearch(list, "three");
System.out.println(index);
}
}
Output
sorted list: [four, one, three, two]
2