Online Java Compiler By
JavaTpoint.com
import java.util.*; public class VectorSetSizeExample1 { public static void main(String arg[]) { //Create an empty vector Vector
vec = new Vector<>(); //Add elements in the vector vec.add(1); vec.add(2); vec.add(3); System.out.println("Components of the vector: "+vec); //Set the new size of the vector vec.setSize(6); //Displaying the vector elements after setting new size System.out.println("Components of the vector after setting new size: "); for (Integer num : vec) { System.out.println("Number = " +num); } } }
Output