Online Java Compiler By
JavaTpoint.com
import java.util.*; public class VectorRemoveExample4 { public static void main(String arg[]) { //Create a first empty vector Vector
vec = new Vector<>(); //Add elements in the first vector vec.add("Facebook"); vec.add("Whatsapp"); vec.add("Twitter"); vec.add("Instagram"); vec.add("Skype"); //Display the elements of a vector System.out.println("Values in vector :" +vec); //Remove the element at index -2 System.out.println("Removed element at index -2: " +vec.remove(-2)); //Again Display the elements of a vector System.out.println("Values in vector after remove: " +vec); } }
Output