/*Vector is a resizable array in Java, found in the java.util package. It is part of the Collection Framework and works like an ArrayList,but it is synchronized, meaning it is safe to use in multi-threaded programs. Key Features of Vector It expands as elements are added. The Vector class is synchronized in nature means it is thread-safe by default. Like an ArrayList, it maintains insertion order. It allows duplicates and nulls. It implements List, RandomAccess, Cloneable and Serializable.*/ import java.util.Vector; public class VectorEx { public static void main(String[] args) { // Create a new vector Vector v = new Vector<>(3, 2); System.out.println(v.capacity()); //3 // Add elements to the vector v.addElement(1); v.addElement(2); v.addElement(3); System.out.println(v); // [1 2 3] // Returns the element at the index 1 in this Vector. System.out.println(v.get(1)); //2 //Tests if vector has no components. System.out.println(v.isEmpty()); // false // Insert an element 0 at index 1 v.insertElementAt(0, 1); // [1 0 2 3] System.out.println(v.capacity()); //5 // Remove the element at index 2 v.removeElementAt(2); // [1 0 3] System.out.println(v.capacity()); //5 //Returns the number of components in this vector. System.out.println(v.size()); //3 // Print the elements of the vector for (int i : v) { System.out.println(i); } } }