Perform Binary Search on Vector - Java Collection Framework

Java examples for Collection Framework:Vector

Description

Perform Binary Search on Vector

Demo Code


import java.util.Vector;
import java.util.Collections;
 
public class Main {
 
  public static void main(String[] args) {

    Vector v = new Vector();
 
    v.add("A");//from www  .  j a va2  s. co  m
    v.add("B");
    v.add("D");
    v.add("E");
    v.add("F");
   
    Collections.sort(v);
    System.out.println("Sorted Vector contains : " + v);
   
    int index = Collections.binarySearch(v,"D");
   
    System.out.println("Element found at : " + index);
  }
}

Result


Related Tutorials