NavigableSet
接口继承自 SortedSet
接口,它在后者的基础上,添加了 4 个 navigation method,用于搜索最匹配目标的 element,分别是 lower()
、 floor()
、 ceiling()
、 higher()
。该接口的方法声明如下所示:
public interface NavigableSet<E> extends SortedSet<E> {
E lower(E e); // element < e,or null if there is no such element.
E floor(E e); // element <= e,or null if there is no such element.
E ceiling(E e); // element >= e,or null if there is no such element.
E higher(E e); // element > e,or null if there is no such element.
E pollFirst(); // Retrieves and removes the first (lowest) element,or returns null if this set is empty.
E pollLast(); // Retrieves and removes the last (highest) element,or returns null if this set is empty.
NavigableSet<E> descendingSet();
Iterator<E> descendingIterator(); // 相当于 descendingSet().iterator()
NavigableSet<E> subSet(E fromElement, boolean fromInclusive,
E toElement, boolean toInclusive);
NavigableSet<E> headSet(E toElement, boolean inclusive);
NavigableSet<E> tailSet(E fromElement, boolean inclusive);
}
此外, NavigableSet
接口还定义了几个新方法,你可以参看上面展示的代码,或查看官方文档,这里不再展开介绍。