1. 程式人生 > >TreeSet的使用【Java集合】

TreeSet的使用【Java集合】

建立

TreeSet() // 預設建構函式。使用該建構函式,TreeSet中的元素按照自然排序進行排列
TreeSet(Collection<? extends E> collection) // 建立的TreeSet包含collection
TreeSet(Comparator<? super E> comparator) // 指定TreeSet的比較器
TreeSet(SortedSet<E> set) // 建立的TreeSet包含set

使用

增
boolean                   add(E object)
boolean                   addAll(Collection<? extends E> collection)
刪
void                      clear()
boolean                   remove(Object object)
查
boolean                   contains(Object object)
E                         first()
boolean                   isEmpty()
E                         last()
E                         pollFirst()
E                         pollLast()
E                         lower(E e)
E                         floor(E e)
E                         ceiling(E e)
E                         higher(E e)
int                       size()
Iterator<E>               iterator()
Iterator<E>               descendingIterator()
SortedSet<E>              headSet(E end)
NavigableSet<E>           descendingSet()
NavigableSet<E>           headSet(E end, boolean endInclusive)
SortedSet<E>              subSet(E start, E end)
NavigableSet<E>           subSet(E start, boolean startInclusive, E end, boolean endInclusive)
NavigableSet<E>           tailSet(E start, boolean startInclusive)
SortedSet<E>              tailSet(E start)
其他
Object                    clone()
Comparator<? super E>     comparator()