Online Java Compiler By
JavaTpoint.com
import java.util.*; public class VectorSetSizeExample2 { public static void main(String arg[]) { //Create an empty vector Vector < String > colors = new Vector < String > (); //Add elements in the vector colors.add("White"); colors.add("Green"); colors.add("Black"); //Displaying the vector elements System.out.println("Components of a vector: "+colors); //Set the new size for the vector colors.setSize(6); //Displaying the vector elements after setting new size System.out.print("Components of a vector after setting new size: "+colors); } }
Output