/*Program using vector class*/
import java.util.*;
class VectorDemo
{
public static void main(String args[])
{
Vector v=new Vector(5,3);
System.out.println("Size:"+v.size());
for(int i=1;i<=7;i++)
{
v.addElement(new Integer(i));
System.out.println("Current size:"+v.size());
System.out.println("Capacity is:"+v.capacity());
}
System.out.println("First Element:"+(Integer)v.firstElement());
System.out.println("Index value is:"+(Integer)v.indexOf(5));
System.out.println("Inserting new element at index 4");
v.insertElementAt(new Integer(5),4);
System.out.println("Last element is:"+(Integer)v.lastElement());
System.out.println("Setting element at index 3");
v.setElementAt(new Integer(7),3);
if(v.contains(new Integer(5)))
System.out.println("Its valid");
else
System.out.println("Not available");
Enumeration vEnum=v.elements();
System.out.println("Total Elements are");
while(vEnum.hasMoreElements())
System.out.println(vEnum.nextElement()+" ");
}
}
import java.util.*;
class VectorDemo
{
public static void main(String args[])
{
Vector v=new Vector(5,3);
System.out.println("Size:"+v.size());
for(int i=1;i<=7;i++)
{
v.addElement(new Integer(i));
System.out.println("Current size:"+v.size());
System.out.println("Capacity is:"+v.capacity());
}
System.out.println("First Element:"+(Integer)v.firstElement());
System.out.println("Index value is:"+(Integer)v.indexOf(5));
System.out.println("Inserting new element at index 4");
v.insertElementAt(new Integer(5),4);
System.out.println("Last element is:"+(Integer)v.lastElement());
System.out.println("Setting element at index 3");
v.setElementAt(new Integer(7),3);
if(v.contains(new Integer(5)))
System.out.println("Its valid");
else
System.out.println("Not available");
Enumeration vEnum=v.elements();
System.out.println("Total Elements are");
while(vEnum.hasMoreElements())
System.out.println(vEnum.nextElement()+" ");
}
}
0 comments:
Post a Comment