Online Java Compiler By
JavaTpoint.com
import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; public class JavaCollectionAddAllExample1 { public static void main(String[] args) { Set
set = new HashSet<>(); List
list = new ArrayList
(); System.out.println("Before applying addAll() : " ); System.out.println("Elements in queue : "+ set); for (int i = 1; i < 11; i++) { int j = i *5; // list.add(j); } System.out.println("Elements in list : "+list); System.out.println(); System.out.println("After applying addAll : "); //will add all the elements in the set which are present in list set.addAll(list); System.out.println("Elements in queue : " + set); System.out.println("Elements in list : "+list); } }
Output