TreeSet

constructor()

Constructs a new, empty tree set, sorted according to the natural ordering of its elements. All elements inserted into the set must implement the Comparable interface. Furthermore, all such elements must be mutually comparable: e1.compareTo(e2) must not throw a ClassCastException for any elements e1 and e2 in the set. If the user attempts to add an element to the set that violates this constraint (for example, the user attempts to add a string element to a set whose elements are integers), the add call will throw a ClassCastException.


constructor(comparator: Comparator<E>)

Constructs a new, empty tree set, sorted according to the specified comparator. All elements inserted into the set must be mutually comparable by the specified comparator: comparator.compare(e1, e2) must not throw a ClassCastException for any elements e1 and e2 in the set. If the user attempts to add an element to the set that violates this constraint, the add call will throw a ClassCastException.

Parameters

comparator

the comparator that will be used to order this set. If null, the natural of the elements will be used.


constructor(c: MutableCollection<E>)

Constructs a new tree set containing the elements in the specified collection, sorted according to the natural ordering of its elements. All elements inserted into the set must implement the Comparable interface. Furthermore, all such elements must be mutually comparable: e1.compareTo(e2) must not throw a ClassCastException for any elements e1 and e2 in the set.

Parameters

c

collection whose elements will comprise the new set

Throws

if the elements in c are not Comparable, or are not mutually comparable

if the specified collection is null


constructor(s: SortedSet<E>)

Constructs a new tree set containing the same elements and using the same ordering as the specified sorted set.

Parameters

s

sorted set whose elements will comprise the new set

Throws

if the specified sorted set is null