The code you provided demonstrates how to remove all elements from one Vector that are also present in another Vector using the removeAll method in Java. Here's a breakdown of what the code does:
As you can see, after calling vec_list1.removeAll(vec_list2) , the elements "Apple" and "Cherry" are removed from vec_list1 because they are present in vec_list2. The resulting vec_list1 contains only the elements that were not present in vec_list2. vec_list2 remains unchanged.
import java.util.*; public class Remove_AllElements { public static void main(String[] args) { Vector vec_list1 = new Vector(); Vector vec_list2 = new Vector(); vec_list1.add("Apple"); vec_list1.add("Banana"); vec_list1.add("Orange"); vec_list1.add("Cherry"); vec_list1.add("Mango"); vec_list2.add("Papaya"); vec_list2.add("Apple"); vec_list2.add("Grapes"); vec_list2.add("Cherry"); System.out.println("Vector List 1 : " + vec_list1); System.out.println("Vector List 2 : " + vec_list2); vec_list1.removeAll(vec_list2); System.out.println("Vector List 1 : " + vec_list1); System.out.println("Vector List 2 : " + vec_list2); } }
Vector List 1 : [Apple, Banana, Orange, Cherry, Mango] Vector List 2 : [Papaya, Apple, Grapes, Cherry] Vector List 1 : [Banana, Orange, Mango] Vector List 2 : [Papaya, Apple, Grapes, Cherry]
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions