Online Java Compiler By
JavaTpoint.com
import java.util.*; public class VectorSetExample1 { 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); vec.add(4); vec.add(6); //Displaying the vector element System.out.println("Vector element before set: " +vec); //Set 5 at 4th index position vec.set(4,5); //Displaying the vector element again System.out.println("Vector element after set: "+vec); } }
Output