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.
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.
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
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
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.