SortedSetsortedSet = new TreeSet<>(); sortedSet.add(5); sortedSet.add(2); sortedSet.add(7);
SortedSetPackage Library: java.util is a core Java package that provides the fundamental collections framework interfaces and classes. It is part of the Java Standard Library.sortedSet = new TreeSet<>(Arrays.asList("apple", "banana", "cherry", "grape", "kiwi")); SortedSet subset = sortedSet.subSet("cherry", "kiwi"); // elements between "cherry" and "kiwi"