Home » Core Java » util » Vector » Remove Vector element example

About Ilias Tsagklis

Avatar photo
Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor at Java Code Geeks.

Remove Vector element example

This is an example of how to remove an element from a Vector. We are using the remove(Object o) API method of Vector. Removing an element from a Vector implies that you should:

  • Create a new Vector.
  • Populate the vector with elements, with add(E e) API method of Vector.
  • Remove an element from the Vector, using remove(Object o) API method. The method removes the first occurrence of the specified element in this Vector. If the Vector does not contain the element, it is unchanged.

Let’s take a look at the code snippet that follows:

package com.javacodegeeks.snippets.core;
import java.util.Vector;
public class RemoveElementFromVector {
  public static void main(String[] args) {
    // Create a Vector and populate it with elements
    Vector vector = new Vector();
    System.out.println("Vector contents : " + vector);

    // boolean remove(Object o) method removes the specific object from the Vector if present and returns true, false otherwise
    boolean removed = vector.remove("element_2");
    System.out.println("Vector contents after removal of element_2 : " + vector);


Vector contents : [element_1, element_2, element_3]
Vector contents after removal of element_2 : [element_1, element_3]

This was an example of how to remove an element from a Vector in Java.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!


1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design


and many more ....


Receive Java & Developer job alerts in your Area

I have read and agree to the terms & conditions


Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments