Java集合源码学习(12)_SortedSet接口和NavigableSet接口

一:SortedSet接口

有序的Set,排序的标准为:设置的Comparator或者自然排序(compareTo()方法);
所有的元素必须实现Comparable接口或者Set设置了Comparator接口;
Method Summary
 Comparator<? super E>comparator() 
          Returns the comparator used to order the elements in this set, or null if this set uses the natural orderingof its elements.
 Efirst() 
          Returns the first (lowest) element currently in this set.
 SortedSet<E>headSet(E toElement) 
          Returns a view of the portion of this set whose elements are strictly less than toElement.
 Elast() 
          Returns the last (highest) element currently in this set.
 SortedSet<E>subSet(E fromElement, E toElement) 
          Returns a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive.
 SortedSet<E>tailSet(E fromElement) 
          Returns a view of the portion of this set whose elements are greater than or equal to fromElement.

二:NavigableSet接口

继承了SortedSet接口
增加了若干接口来获得离某个元素最近的一些元素;
Method Summary
 Eceiling(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.
 Iterator<E>descendingIterator() 
          Returns an iterator over the elements in this set, in descending order.
 NavigableSet<E>descendingSet() 
          Returns a reverse order view of the elements contained in this set.
 Efloor(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.
 SortedSet<E>headSet(E toElement) 
          Returns a view of the portion of this set whose elements are strictly less than toElement.
 NavigableSet<E>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.
 Ehigher(E e) 
          Returns the least element in this set strictly greater than the given element, or null if there is no such element.
 Iterator<E>iterator() 
          Returns an iterator over the elements in this set, in ascending order.
 Elower(E e) 
          Returns the greatest element in this set strictly less than the given element, or null if there is no such element.
 EpollFirst() 
          Retrieves and removes the first (lowest) element, or returns null if this set is empty.
 EpollLast() 
          Retrieves and removes the last (highest) element, or returns null if this set is empty.
 NavigableSet<E>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.
 SortedSet<E>subSet(E fromElement, E toElement) 
          Returns a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive.
 SortedSet<E>tailSet(E fromElement) 
          Returns a view of the portion of this set whose elements are greater than or equal to fromElement.
 NavigableSet<E>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.

 三:TreeMap

内部是通过NavigableMap的形式来存储的;
public class TreeSet<E> extends AbstractSet<E> implements NavigableSet<E>, Cloneable, java.io.Serializable {
	
	private transient NavigableMap<E, Object> m;


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值