Create a list with an ordered list of strings
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
public class Main {
public static void main(String[] argv) {
List<String> sortedList = new LinkedList<String>();
sortedList.addAll(Arrays.asList(new String[] { "a", "b", "c", "d" }));
int index = Collections.binarySearch(sortedList, "c");
System.out.println(index);
index = Collections.binarySearch(sortedList, "e");
System.out.println(index);
}
}
Related examples in the same category