Online Java Compiler By
JavaTpoint.com
import java.util.Vector; public class VectorRemoveAllExample2 { public static void main(String arg[]) { //Create an empty Vec1 Vector
vec1 = new Vector
(); //Add elements in the Vector1 vec1.add("A"); vec1.add("B"); vec1.add("C"); vec1.add("10"); vec1.add("20"); //Displaying the Vector1 elements System.out.println("Vector: " + vec1); //Create an empty Vec2 Vector
vec2 = new Vector
(); //Add elements in the Vector2 vec2.add("A"); vec2.add("B"); vec2.add("C"); //use removeAll() method boolean changed = vec1.removeAll(vec2); //Print the result if (changed) System.out.println("Collection removed"); else System.out.println("Collection not removed"); //Display the final Vector System.out.println("Final Vector: " + vec1); } }
Output