Javatpoint Logo
Javatpoint Logo

Java Vector remove() Method

The remove() Java Vector class method is used to remove the specified element from the vector. There are two different types of Java remove() method which can be differentiated depending on its parameter. These are:

  1. Java Vector remove(int index) Method
  2. Java Vector remove(Object o) Method

remove(int index) Method:

This method remove the element at the specified position in this vector.

remove(Object o) Method:

This method remove the first occurrence of the specified element in this vector. If the vector does not contain the element, it is unchanged.


Following is the declaration of remove() method:


Parameter Description Required/Optional
index It is an index of the element which will be removed. Required
obj It is an element which will be removed from the vector if present. Required


The remove(int index) method returns the element that was removed.

The remove(Object obj) method returns true if the vector contained the specified element.


ArrayIndexOutOfBoundsException- This method has thrown an exception if the index is out of range i.e. (index < 0 || index >= size()).

Compatibility Version

Java 1.2 and above

Example 1

Test it Now


Values in vector: [100, 200, 300, 200, 400]
Remove first occourence of element 200: true
Values in vector: [100, 300, 200, 400]

Example 2

Test it Now


Elements of the Vector before remove: [Java, Android, JavaScript, Java]
Is the removal successful? true
Elements of the Vector after remove: [Android, JavaScript, Java]

Example 3

Test it Now


Values in vector :[3, 5, 3, 4]
Removed element at index 2 is: 3
Values in vector after remove: [3, 5, 4]

Example 4

Test it Now


Values in vector :[Facebook, Whatsapp, Twitter, Instagram, Skype]
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -2
	at java.base/java.util.Vector.elementData(
	at java.base/java.util.Vector.remove(
	at myPackage.VectorRemoveExample4.main(

Next TopicJava Vector

Youtube For Videos Join Our Youtube Channel: Join Now


  • Send your Feedback to

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA