Wednesday, March 11, 2015

Updating Linked List and Vector Maximum and Binary in java pro



Updating Linked List
 
import java.util.LinkedList;
public class MainClass 
{
   public static void main(String[] a) 
   {
      LinkedList officers = new LinkedList();
      officers.add("B");
      officers.add("B");
      officers.add("T");
      officers.add("H");
      officers.add("P");
      System.out.println(officers);
      officers.set(2, "M");
      System.out.println(officers);
   }
}
 
Vector Maximum
 
import java.util.Collections;
import java.util.Vector;
public class Main
 {
   public static void main(String[] args) 
   {
      Vector v = new Vector();
      v.add(new Double("3.4324"));
      v.add(new Double("3.3532"));
      v.add(new Double("3.342"));
      v.add(new Double("3.349"));
      v.add(new Double("2.3"));
      Object obj = Collections.max(v);
      System.out.println("The max element is:"+obj);
   }
}
 
Vector Binary
 
import java.util.Collections;
import java.util.Vector;
public class Main 
{
   public static void main(String[] args) 
    {
      Vector v = new Vector();
      v.add("X");
      v.add("M");
      v.add("D");
      v.add("A");
      v.add("O");
      Collections.sort(v);
      System.out.println(v);
      int index = Collections.binarySearch(v, "D");
      System.out.println("Element found at : " + index);
   }
}

No comments:

Post a Comment