vector in Core Java

import java.util.*;
class vector
{
public static void main(String args[])
{
//Vector vector = new Vector();//By default initial Capacity is of 10 elements
//Vector vector = new Vector(5);//Initial Capacity is of 5 elements grow by initial capacity
Vector vector = new Vector(5,2);//Initial Capacity is of 5 elements grow by 2

System.out.println("Capacity: " + vector.capacity());
System.out.println("Size: " + vector.size());
String a=new String ("Happy");
vector.addElement(a);
vector.addElement(new Integer(1));
vector.addElement(new Double(3.14159));
vector.addElement(new Float(3.14159));
vector.addElement(new String("NIIT"));
vector.addElement(new String("STG"));
System.out.println("=======================================");
System.out.println("Size: " + vector.size());
System.out.println("Capacity: " + vector.capacity());
System.out.println("Hello Element :"+vector.elementAt(0));

//vector.insertElementAt(new String("Raj"),0);
vector.setElementAt(new String("Raj"),0);
System.out.println("After Insert :"+vector.elementAt(0));
System.out.println("After Insert :"+vector.elementAt(1));

System.out.println("Before removing First Element :"+vector.elementAt(0));
vector.removeElementAt(0);

System.out.println("After removing First Element :"+vector.elementAt(0));
System.out.println("Element :"+vector.elementAt(0));

System.out.println("First item: " + vector.firstElement());
System.out.println("II Element is:"+vector.elementAt(1));
System.out.println("Last item: " +vector.lastElement());

if(vector.contains(new String("NIIT1")))
System.out.println("Found a 1.");
else
System.out.println("Not Found a 1.");
}
}

Comments

Popular Posts