java.util.Collections.binarySearch Comparator


java.util.Collections.binarySearch Comparator

package com.codingdict;

import java.util.*;

public class CollectionsDemo {
   public static void main(String args[]) {

      // create arraylist       
      ArrayList<String> arlst=new ArrayList<String>();

      // populate the list
      arlst.add("TP");
      arlst.add("PROVIDES");
      arlst.add("QUALITY");
      arlst.add("TUTORIALS");

      // search for key 'TUTORIALS' with natural ordering
      int index = Collections.binarySearch(arlst, "TUTORIALS", null);     

      System.out.println("'TUTORIALS' is available at index: "+index);
   }    
}