import java.util.Vector; public class MyVectorExample { public static void main(String[] args) { VectormyVector = new Vector<>(); // add elements to the vector myVector.add(10); myVector.add(20); myVector.add(30); // print the vector System.out.println("My vector contains: " + myVector); } }
import java.util.Vector; public class MyVectorExample { public static void main(String[] args) { VectorIn this example, we create a Vector of strings and add four elements to it using the add() method. We then iterate over the Vector using a for loop and check if each element starts with the letter "b". If it does, we remove that element from the Vector using the remove() method. Finally, we print the contents of the Vector to the console. In conclusion, java.util Vector is a useful collection in Java that provides thread-safe access to an ordered list of elements. It is part of the Java Standard Library and can be used by importing the java.util package.myVector = new Vector<>(); // add elements to the vector myVector.add("cat"); myVector.add("dog"); myVector.add("bat"); myVector.add("rat"); // remove elements that start with "b" for (int i = 0; i < myVector.size(); i++) { String element = myVector.elementAt(i); if (element.startsWith("b")) { myVector.remove(i); i--; } } // print the vector System.out.println("My vector contains: " + myVector); } }