Java Collections.binarySearch(List <? extends Comparable <? super T>> list, T key)
Syntax
Collections.binarySearch(List <? extends Comparable <? super T>> list, T key) has the following syntax.
public static <T> int binarySearch(List <? extends Comparable <? super T>> list, T key)
Example
In the following code shows how to use Collections.binarySearch(List <? extends Comparable <? super T>> list, T key) method.
/*from ww w .j ava 2 s. co m*/
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Main {
public static void main(String args[]) {
List<String> arlst=new ArrayList<String> ();
arlst.add("CSS");
arlst.add("HTML");
arlst.add("PHP");
// search the list for key
int index=Collections.binarySearch(arlst, "HTML");
System.out.println(index);
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.util »
Java Tutorial »
java.util »