TreeMap的使用【Java集合】

创建

TreeMap() // 默认构造函数。使用该构造函数,TreeMap中的元素按照自然排序进行排列。
TreeMap(Map<? extends K, ? extends V> copyFrom) // 创建的TreeMap包含Map
TreeMap(Comparator<? super K> comparator) // 指定Tree的比较器
TreeMap(SortedMap<K, ? extends V> copyFrom) // 创建的TreeSet包含copyFrom

使用

增
Entry<K, V>                pollFirstEntry()
Entry<K, V>                pollLastEntry()
V                          put(K key, V value)
删
void                       clear()
V                          remove(Object key)
查
Entry<K, V>                ceilingEntry(K key)
K                          ceilingKey(K key)
boolean                    containsKey(Object key)
NavigableSet<K>            descendingKeySet()
NavigableMap<K, V>         descendingMap()
Set<Entry<K, V>>           entrySet()
Entry<K, V>                firstEntry()
K                          firstKey()
Entry<K, V>                floorEntry(K key)
K                          floorKey(K key)
V                          get(Object key)
NavigableMap<K, V>         headMap(K to, boolean inclusive)
SortedMap<K, V>            headMap(K toExclusive)
Entry<K, V>                higherEntry(K key)
K                          higherKey(K key)
boolean                    isEmpty()
Set<K>                     keySet()
Entry<K, V>                lastEntry()
K                          lastKey()
Entry<K, V>                lowerEntry(K key)
K                          lowerKey(K key)
NavigableSet<K>            navigableKeySet()
int                        size()
SortedMap<K, V>            subMap(K fromInclusive, K toExclusive)
NavigableMap<K, V>         subMap(K from, boolean fromInclusive, K to, boolean toInclusive)
NavigableMap<K, V>         tailMap(K from, boolean inclusive)
SortedMap<K, V>            tailMap(K fromInclusive)
其他
Object                     clone()
Comparator<? super K>      comparator()

猜你喜欢

转载自blog.csdn.net/SongBai1997/article/details/82988352