Implement a Java program to accomplish the following task using Vector Class 1. To add two integers, two float, two characters, two string objects. 2. To search a particular object of the Vector. 3. To display all objects along with their index position. (for eg. Character 'A' is present at position 4 in the Vector). 4. To delete all objects from Vector.

import java.util.*;
class Exp5_2
{
 public static void main(String[] args) 
 {
  Vector v = new Vector();
  v.addElement(new Integer(10));
  v.addElement(new Integer(20));
  v.addElement(new Float(3.14F));
  v.addElement(new Float(18.45F));
  v.addElement(new Character('A'));
  v.addElement(new Character('J'));
  v.addElement(new String("Java"));
  v.addElement(new String("Practicals"));
  String key = "Java";
  int index = v.indexOf(key);
  if(index == -1)
   System.out.println("Element " + key +" not found");
  else
   System.out.println("Element " + key +" found");
  Enumeration vEnum = v.elements();
  System.out.println("Elements in Vector are: ");
  for(int i=0; vEnum.hasMoreElements(); i++)
   System.out.println("Element at index " + i +" is : " + vEnum.nextElement());
  v.removeAllElements();
 }
}
/*  OUTPUT!!!
Element Java found
Elements in Vector are:
Element at index 0 is : 10
Element at index 1 is : 20
Element at index 2 is : 3.14
Element at index 3 is : 18.45
Element at index 4 is : A
Element at index 5 is : J
Element at index 6 is : Java
Element at index 7 is : Practicals
*/
Copyright © LetML. Blogger Templates Designed by OddThemes