import java.util.SortedSet; import java.util.TreeSet; public class SortedSetExample { public static void main(String[] args) { SortedSetset = new TreeSet<>(); set.add("apple"); set.add("banana"); set.add("orange"); System.out.println(set); // [apple, banana, orange] } }
import java.util.SortedSet; import java.util.TreeSet; public class SortedSetExample { public static void main(String[] args) { SortedSetThis example demonstrates the use of contains() method to check if a particular element exists in the SortedSet or not. In Java, the SortedSet along with TreeSet implementation can be found under the java.util package.set = new TreeSet<>(); set.add("apple"); set.add("banana"); set.add("orange"); System.out.println(set.contains("apple")); // true System.out.println(set.contains("grape")); // false } }