Java示例二进制搜索矢量


Java示例二进制搜索矢量

import java.util.Vector;

import java.util.Collections;



public class Demo {

   public static void main(String[] args) {

      Vector vec = new Vector();

      vec.add("X");

      vec.add("M");

      vec.add("D");

      vec.add("A");

      vec.add("O");



      Collections.sort(vec);

      System.out.println("Sorted Vector: " + vec);

      int found = Collections.binarySearch(vec, "D");

      System.out.println("Element found at : " + found);

   }

}