// Java program to demonstrate how retainAll()// method returns boolean value with Setsimportjava.util.*;publicclassGeeks{publicstaticvoidmain(String[]args){// Create two sets of integersSet<Integer>s1=newHashSet<>(Arrays.asList(1,2,3,4,5));Set<Integer>s2=newHashSet<>(Arrays.asList(3,4,5,6,7));System.out.println("Set 1: "+s1);System.out.println("Set 2: "+s2);// Call retainAll and check the return valuebooleanb=s1.retainAll(s2);System.out.println("Set 1 after retainAll (common elements): "+s1);System.out.println("Was the set modified? "+b);// Modify s1 to contain all elements from s2s1=newHashSet<>(Arrays.asList(3,4,5));// Now retain elements common between s1 and s2b=s1.retainAll(s2);System.out.println("Set 1 after retainAll (common elements): "+s1);System.out.println("Was the set modified? "+b);}}