import java.util.Vector; public class Main { public static void main(String[] args) { Vectorv = new Vector (); v.add("foo"); v.add("bar"); v.add("baz"); String element = v.elementAt(1); System.out.println(element); } }
import java.util.Vector; public class Main { public static void main(String[] args) { VectorThis code creates a vector of integers, adds three elements to it, and then retrieves the element at index 2 (i.e. the third element in the vector) using the elementAt() method. In this case, the output will be 3. The elementAt() method is part of the java.util package library.v = new Vector (); v.add(1); v.add(2); v.add(3); int element = v.elementAt(2); System.out.println(element); } }