import java.util.Vector; public class Main { public static void main(String[] args) { Vectornumbers = new Vector (); numbers.add(10); numbers.add(20); numbers.add(30); System.out.println(numbers.get(1)); } }
import java.util.Vector; public class Main { public static void main(String[] args) { VectorOutput: Orange In this example, we create a Vector of strings and add some fruits to it. We then use the get() method to retrieve the fruit at index 2 (which is the third fruit) and print it to the console. We can determine that the get() method belongs to the java.util package by looking at its import statement at the beginning of the code examples.fruits = new Vector (); fruits.add("Apple"); fruits.add("Banana"); fruits.add("Orange"); String fruit = fruits.get(2); System.out.println(fruit); } }