import java.util.Vector; public class VectorExample { public static void main(String[] args) { Vectornumbers = new Vector (); numbers.add(10); numbers.add(20); numbers.add(30); numbers.add(40); numbers.add(50); System.out.println("Vector contents before removing an element: " + numbers); boolean result = numbers.removeElement(30); if(result) { System.out.println("Element 30 is removed from the vector."); } else { System.out.println("Element 30 is not found in the vector."); } System.out.println("Vector contents after removing an element: " + numbers); } }
Vector contents before removing an element: [10, 20, 30, 40, 50] Element 30 is removed from the vector. Vector contents after removing an element: [10, 20, 40, 50]
import java.util.Vector; public class VectorExample { public static void main(String[] args) { Vectornames = new Vector (); names.add("John"); names.add("Mary"); names.add("Sarah"); names.add("David"); System.out.println("Vector contents before removing an element: " + names); boolean result = names.removeElement("Sarah"); if(result) { System.out.println("Element 'Sarah' is removed from the vector."); } else { System.out.println("Element 'Sarah' is not found in the vector."); } System.out.println("Vector contents after removing an element: " + names); } }
Vector contents before removing an element: [John, Mary, Sarah, David] Element 'Sarah' is removed from the vector. Vector contents after removing an element: [John, Mary, David]The Vector class is a part of the java.util package library.