Vector removeElement() method in Java with Example Last Updated : 24 May, 2023 Comments Improve Suggest changes Like Article Like Report The java.util.Vector.removeElement() method is used to remove first occurrence of particular object. If object is not found then it returns false else it returns true. If a particular object is present inside vector and removeElement() method call on that vector element then this method reduces vector size by 1. Syntax: public boolean removeElement(Object obj) Parameters: This function accepts object as parameter which is to be removed. Return Type: On Successful of deletion this function returns True otherwise this function returns False. Exceptions: This method does not raise any exception. Below programs illustrates the Vector.removeElement() function. Program 1: Java // Java program to understand // about vector.removeElement() function // because vector is present in this package import java.util.*; // Driver Code public class vector_demo { // main method begins here public static void main(String[] args) { // creating vector type object Vector<Integer> v = new Vector<Integer>(); // inserting elements into the vector v.add(1); v.add(2); v.add(3); v.add(4); v.add(5); v.add(6); // printing vector before deleting element System.out.println("Before deleting"); System.out.println("Vector: " + v); System.out.println("Size: " + v.size()); System.out.println("\nAfter deleting"); // trying to deleting object 3 boolean flag = v.removeElement(3); if (flag) { System.out.println("Element '3' has been removed"); } else { System.out.println("Element '3' is not present in Vector"); } System.out.println("Vector: " + v); System.out.println("Size: " + v.size()); } } Output:Before deleting Vector: [1, 2, 3, 4, 5, 6] Size: 6 After deleting Element '3' has been removed Vector: [1, 2, 4, 5, 6] Size: 5 Example 2: Java // Java program to understand // about vector.removeElement() function // because vector is present in this package import java.util.*; // Driver Code public class vector_demo { // main method begins here public static void main(String[] args) { // creating vector type object Vector<Integer> v = new Vector<Integer>(); // inserting elements into the vector v.add(1); v.add(2); v.add(3); v.add(4); v.add(5); v.add(6); // printing vector before deleting element System.out.println("Before deleting"); System.out.println("Vector: " + v); System.out.println("Size: " + v.size()); System.out.println("\nAfter deleting"); // trying to deleting object 15 boolean flag = v.removeElement(15); // since object 15 is not present flag will be false if (flag) { System.out.println("Element '15' has been removed"); } else { System.out.println("Element '15' is not present in Vector"); } System.out.println("Vector: " + v); System.out.println("Size: " + v.size()); } } Output:Before deleting Vector: [1, 2, 3, 4, 5, 6] Size: 6 After deleting Element '15' is not present in Vector Vector: [1, 2, 3, 4, 5, 6] Size: 6 Time complexity: O(n). // n is the size of the vector.Space complexity: O(1). Comment More infoAdvertise with us Next Article Vector removeElement() method in Java with Example ankit15697 Follow Improve Article Tags : Java Technical Scripter Java-Collections Java - util package Java-Functions Java-Vector +2 More Practice Tags : JavaJava-Collections Similar Reads Vector equals() Method in Java The java.util.vector.equals(Object obj) method of Vector class in Java is used verify the equality of an Object with a vector and compare them. The list returns true only if both Vector contains same elements with same order. Syntax: first_vector.equals(second_vector) Parameters: This method accepts 2 min read Vector firstElement() Method in Java The java.util.vector.firstElement() method in Java is used to retrieve or fetch the first element of the Vector. It returns the element present at the 0th index of the vector Syntax: Vector.firstElement() Parameters: The method does not take any parameter. Return Value: The method returns the first 2 min read Vector forEach() method in Java The forEach() method of Vector is used to perform a given action for every element of the Iterable of Vector until all elements have been Processed by the method or an exception occurs. The operations are performed in the order of iteration if the order is specified by the method. Exceptions thrown 3 min read Vector hashCode() Method in Java The java.util.vector.hashCode() method in Java is used to get the hashcode value of this vector. Syntax: Vector.hashCode() Parameters: The method does not take any parameter. Return Value: The method returns hash code value of this Vector which is of Integer type. Below programs illustrate the Java. 2 min read Vector indexOf() Method in Java The java.util.vector.indexOf(Object element) method is used to check and find the occurrence of a particular element in the vector. If the element is present then the index of the first occurrence of the element is returned otherwise -1 is returned if the vector does not contain the element. Syntax: 3 min read Vector insertElementAt() Method in Java with Examples insertElementAt() method of Vector class present inside java.util package is used to insert a particular element at the specified index of the Vector. Both the element and the position are passed as the parameters. If an element is inserted at a specified index, then all the elements are pushed upwa 3 min read Vector isEmpty() Method in Java The Java.util.Vector.isEmpty() method in Java is used to check and verify if a Vector is empty or not. It returns True if the Vector is empty else it returns False. Syntax: Vector.isEmpty() Parameters: This method does not take any parameter. Return Value: This function returns True if the Vectoris 2 min read Vector iterator() method in Java with Examples iterator() method of Vector class that is present inside java.util package is used to return an iterator of the same elements as that of the Vector. The elements are returned in random order from what was present in the vector. Syntax: Iterator iterate_value = Vector.iterator(); Parameters: The func 2 min read Vector lastElement() Method in Java The java.util.vector.lastElement() method in Java is used to retrieve or fetch the last element of the Vector. It returns the element present at the last index of the vector. Syntax: Vector.lastElement() Parameters: The method does not take any parameter. Return Value: The method returns the last el 2 min read Vector lastIndexOf() Method in Java The Java.util.Vector.lastIndexOf(Object element) method is used to check and find the occurrence of a particular element in the vector. If the element is present in the vector then the lastIndexOf() method returns the index of last occurrence of the element otherwise it returns -1. This method is us 2 min read Like