Engineering Full Stack Apps with Java and JavaScript
TreeSet Class implements NavigableSet and is based on a TreeMap.
The elements are ordered using their natural ordering, or by a Comparator
Comparator can provided at set creation time through one of the overloaded constructors.
Provides guaranteed log(n) time cost for the basic operations like add, remove and contains.
Ordering maintained by a set must be consistent with equals
The behavior of a set is well-defined even if its ordering is inconsistent with equals; it just fails to obey the general contract of the Set interface.
is not synchronized.
Could synchronize on some object that naturally encapsulates the set, or "wrapped" using the Collections.synchronizedSortedSet method.
This is best done at creation time.
The iterators returned by this class's iterator method are fail-fast, but the fail-fast behavior of an iterator cannot be guaranteed.
ceiling(E e)
Returns the least element in this set greater than or equal to the given element, or null if there is no such element.
clone()
Returns a shallow copy of this TreeSet instance.
comparator()
Returns the comparator used to order the elements in this set, or null if this set uses the natural ordering of its elements.
descendingIterator()
Returns an iterator over the elements in this set in descending order.
descendingSet()
Returns a reverse order view of the elements contained in this set.
first()
Returns the first (lowest) element currently in this set.
floor(E e)
Returns the greatest element in this set less than or equal to the given element, or null if there is no such element.
headSet(E toElement)
Returns a view of the portion of this set whose elements are strictly less than toElement.
headSet(E toElement, boolean inclusive)
Returns a view of the portion of this set whose elements are less than (or equal to, if inclusive is true) toElement.
higher(E e)
Returns the least element in this set strictly greater than the given element, or null if there is no such element.
last()
Returns the last (highest) element currently in this set.
lower(E e)
Returns the greatest element in this set strictly less than the given element, or null if there is no such element.
pollFirst()
Retrieves and removes the first (lowest) element, or returns null if this set is empty.
pollLast()
Retrieves and removes the last (highest) element, or returns null if this set is empty.
spliterator()
Creates a late-binding and fail-fast Spliterator over the elements in this set.
subSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive)
Returns a view of the portion of this set whose elements range from fromElement to toElement.
subSet(E fromElement, E toElement)
Returns a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive.
tailSet(E fromElement)
Returns a view of the portion of this set whose elements are greater than or equal to fromElement.
tailSet(E fromElement, boolean inclusive)
Returns a view of the portion of this set whose elements are greater than (or equal to, if inclusive is true) fromElement.
Other elements include: add(E e), addAll(Collection<? extends E> c), clear(), contains(Object o), isEmpty(), iterator(), remove(Object o), size().