Online Java Compiler By
JavaTpoint.com
import java.util.*; public class CollectionsBinarySearchExample2 { public static void main(String[] args) { //Create list ArrayList
arrlist = new ArrayList
(); arrlist.add(10); arrlist.add(-20); arrlist.add(30); arrlist.add(-40); arrlist.add(50); //Print List System.out.println("Provided List are: "+arrlist); //Search the list for key '-20' int index = Collections.binarySearch(arrlist, -20, Collections.reverseOrder()); System.out.println("Index '-20' is available at position: "+index); } }
Output