Vector Class in Java Collection
Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java
Program 1
import java.util.*;
class TestVector
{
public static void main(String args[])
{
Vector<Integer> V=new Vector<Integer>();
V.add(10); // Collection
V.add(20);
V.add(30);
V.add(40);
V.add(2,150); //List
V.addElement(200); // Vector
//System.out.println(V.elementAt(2));// Vector
// System.out.println(V.firstElement()); // Vector
// System.out.println(V.lastElement()); // Vector
System.out.println(V);
//Integer I=30;
// System.out.println(V.remove(I)); // Collection Argument is Object Return is boolean
// System.out.println(V.remove(4)); // List Argument is index Return is Object
// System.out.println(V.remove(4)); // List Argument is index Return is Object
// V.removeElementAt(4); /// Vector return type is void
// V.clear(); /// Collection
V.removeAllElements(); // Vector
System.out.println(V);
}
}
// ArrayList<Integer>A=new ArrayList<Integer>();
// A.add(10);
// A.add(20);
// A.add(30);
// A.add(40);
// Vector<Integer>V=new Vector<Integer>(A);
// System.out.println(V);
// for(int i=0;i<V.size();i++)
// {
//System.out.println(V.elementAt(i)); // Vector
// System.out.println(V.get(9)); //Collection
// }
We work very hard to provide you quality material
Could you take 15 seconds and share your happy experience on Google

