TreeSet containsAll() method in Java with Example Last Updated : 27 Dec, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report The containsAll() method of Java TreeSet is used to check whether two sets contain the same elements or not. It takes one set as a parameter and returns True if all of the elements of this set is present in the other set. Syntax: public boolean containsAll(Collection C) Parameters: The parameter C is a Collection. This parameter refers to the set whose elements occurrence is needed to be checked in this set. Return Value: The method returns True if this set contains all the elements of other set otherwise it returns False. Below programs illustrate the TreeSet.containsAll() method: Program 1: Java // Java code to illustrate // TreeSet containsAll() import java.util.*; class TreeSetDemo { public static void main(String args[]) { // Creating an empty set TreeSet<String> set = new TreeSet<String>(); // Use add() method to // add elements in the set set.add("Geeks"); set.add("for"); set.add("Geeks"); set.add("10"); set.add("20"); // prints the set System.out.println("TreeSet 1: " + set); // Creating another empty set TreeSet<String> set2 = new TreeSet<String>(); // Use add() method to // add elements in the set set2.add("Geeks"); set2.add("for"); set2.add("Geeks"); set2.add("10"); set2.add("20"); // prints the set System.out.println("TreeSet 2: " + set2); // Check if the set // contains same elements System.out.println("\nDoes set 1 contains set 2: " + set.containsAll(set2)); } } Output: TreeSet 1: [10, 20, Geeks, for] TreeSet 2: [10, 20, Geeks, for] Does set 1 contains set 2: true Program 2: Java // Java code to illustrate boolean containsAll() import java.util.*; class TreeSetDemo { public static void main(String args[]) { // Creating an empty set TreeSet<String> set = new TreeSet<String>(); // Use add() method to // add elements in the set set.add("Geeks"); set.add("for"); set.add("Geeks"); // prints the set System.out.println("TreeSet 1: " + set); // Creating another empty set TreeSet<String> set2 = new TreeSet<String>(); // Use add() method to // add elements in the set set2.add("10"); set2.add("20"); // prints the set System.out.println("TreeSet 2: " + set2); // Check if the set // contains same elements System.out.println("\nDoes set 1 contains set 2: " + set.containsAll(set2)); } } Output: TreeSet 1: [Geeks, for] TreeSet 2: [10, 20] Does set 1 contains set 2: false Comment More infoAdvertise with us Next Article Set contains() method in Java with Examples C code_r Follow Improve Article Tags : Java Java-Collections Java - util package Java-Functions java-treeset +1 More Practice Tags : JavaJava-Collections Similar Reads TreeSet contains() Method in Java With Examples TreeSet is one of the most important implementations of the SortedSet interface in Java that uses a Tree for storage. The ordering of the elements is maintained by a set using their natural ordering whether or not an explicit comparator is provided. This must be consistent with equals if it is to co 3 min read SortedSet containsAll() method in Java with Examples The containsAll() method of Java SortedSet is used to check whether two sets contain the same elements or not. It takes one set as a parameter and returns True if all of the elements of this set is present in the other set. Syntax: public boolean containsAll(Collection C) Parameters: The parameter C 2 min read Stack containsAll() method in Java with Example The containsAll() method of Java Stack is used to check whether two stacks contain the same elements or not. It takes one stack as a parameter and returns True if all of the elements of this stack is present in the other stack. Syntax: public boolean containsAll(Collection C) Parameters: The paramet 2 min read Set contains() method in Java with Examples The Java.util.Set.contains() method is used to check whether a specific element is present in the Set or not. So basically it is used to check if a Set contains any particular element. Syntax: boolean contains(Object element) Parameters: The parameter element is of the type of Set. This is the eleme 2 min read TreeMap containsValue() Method in Java With Examples In Java, containsValue() method of the TreeMap class is used to check whether a particular value is being mapped by any key in the TreeMap. It takes the value as a parameter and returns True if that value is mapped by any of the keys in the map. --> java.util Package --> TreeMap class --> c 3 min read SortedSet contains() method in Java with Examples The contains() method is used to check whether a specific element is present in the SortedSet or not. So basically it is used to check if a SortedSet contains any particular element. Syntax: boolean contains(Object element) Parameters: The parameter element is of the type of SortedSet. This is the e 2 min read Like