66
Java Vector removeElement() Method
The removeElement() method of Java Vector class is used to remove the first (lowest-indexed) occurrence of the argument from this vector. Removing an element decreases the vector size by one.
Syntax
Following is the declaration of removeElement() method:
Parameter
Parameter | Description | Required/Optional |
---|---|---|
obj | It is an element which will be removed from the vector. | Required |
Return
The removeElement() method returns true if the argument was a component of the vector, otherwise returns false.
Exceptions
NA
Compatibility Version
Java 1.2 and above
Example 1
Output:
Vector element before removal: [1, 2, 3, 4, 5, 6] Vector element after removal: [1, 2, 3, 4, 6]
Example 2
Output:
The elements of a Vector before remove: [Rahul, Karan, Rahul, Rohan] Is the removal successful?? true The elements of the Vector after remove: [Karan, Rahul, Rohan]
Next TopicJava Vector