Vector Remove Element - Java

To remove element from Vector we will use method


See Example:

import java.util.Iterator;
import java.util.Vector;

public class Example {

public static void main(String args[]) {
   
     Vector<String> vec = addVector();
 
}
//declare method to get Vector 
public static Vector<String> addVector(){
/* Vector of initial */
 Vector<String> vectors = new Vector<String>();
 /* Adding elements to a vector*/
 vectors.addElement("Item1");
 vectors.addElement("Item2");
 vectors.addElement("Item3");
 vectors.addElement("Item4");
 vectors.addElement("Item5");
 System.out.println("Vector elements : "+vectors);
 System.out.println("Vector Size Before Remove : "+vectors.size());
 //remove first element "Item1" of index zero
 System.out.println("Removed element: "+vectors.remove(0));
 System.out.println("Vector Size after Remove : "+vectors.size());

 return vectors;

}

}

//result :

Vector elements : [Item1, Item2, Item3, Item4, Item5]
Vector Size Before Remove : 5
Removed element: Item1
Vector Size after Remove : 4


EmoticonEmoticon