Skip to content

Most visited

Recently visited

navigation
Added in API level 1

SortedMap

public interface SortedMap
implements Map<K, V>

java.util.SortedMap<K, V>
Known Indirect Subclasses


A map that has its keys ordered. The sorting is according to either the natural ordering of its keys or the ordering given by a specified comparator.

Summary

Public methods

abstract Comparator<? super K> comparator()

Returns the comparator used to compare keys in this sorted map, or null if the natural ordering is in use.

abstract K firstKey()

Returns the least key in this sorted map.

abstract SortedMap<K, V> headMap(K endKey)

Returns a sorted map over a range of this sorted map with all keys that are less than the specified endKey.

abstract K lastKey()

Returns the greatest key in this sorted map.

abstract SortedMap<K, V> subMap(K startKey, K endKey)

Returns a sorted map over a range of this sorted map with all keys greater than or equal to the specified startKey and less than the specified endKey.

abstract SortedMap<K, V> tailMap(K startKey)

Returns a sorted map over a range of this sorted map with all keys that are greater than or equal to the specified startKey.

Inherited methods

From interface java.util.Map

Public methods

comparator

Added in API level 1
Comparator<? super K> comparator ()

Returns the comparator used to compare keys in this sorted map, or null if the natural ordering is in use.

Returns
Comparator<? super K>

firstKey

Added in API level 1
K firstKey ()

Returns the least key in this sorted map.

Returns
K
Throws
NoSuchElementException if this sorted map is empty.

headMap

Added in API level 1
SortedMap<K, V> headMap (K endKey)

Returns a sorted map over a range of this sorted map with all keys that are less than the specified endKey. Changes to the returned sorted map are reflected in this sorted map and vice versa.

Note: The returned map will not allow an insertion of a key outside the specified range.

Parameters
endKey K: the high boundary of the range specified.
Returns
SortedMap<K, V> a sorted map where the keys are less than endKey.
Throws
ClassCastException if the class of the end key is inappropriate for this sorted map.
NullPointerException if the end key is null and this sorted map does not support null keys.
IllegalArgumentException if this map is itself a sorted map over a range of another map and the specified key is outside of its range.

lastKey

Added in API level 1
K lastKey ()

Returns the greatest key in this sorted map.

Returns
K
Throws
NoSuchElementException if this sorted map is empty.

subMap

Added in API level 1
SortedMap<K, V> subMap (K startKey, 
                K endKey)

Returns a sorted map over a range of this sorted map with all keys greater than or equal to the specified startKey and less than the specified endKey. Changes to the returned sorted map are reflected in this sorted map and vice versa.

Note: The returned map will not allow an insertion of a key outside the specified range.

Parameters
startKey K: the low boundary of the range (inclusive).
endKey K: the high boundary of the range (exclusive),
Returns
SortedMap<K, V> a sorted map with the key from the specified range.
Throws
ClassCastException if the class of the start or end key is inappropriate for this sorted map.
NullPointerException if the start or end key is null and this sorted map does not support null keys.
IllegalArgumentException if the start key is greater than the end key, or if this map is itself a sorted map over a range of another sorted map and the specified range is outside of its range.

tailMap

Added in API level 1
SortedMap<K, V> tailMap (K startKey)

Returns a sorted map over a range of this sorted map with all keys that are greater than or equal to the specified startKey. Changes to the returned sorted map are reflected in this sorted map and vice versa.

Note: The returned map will not allow an insertion of a key outside the specified range.

Parameters
startKey K: the low boundary of the range specified.
Returns
SortedMap<K, V> a sorted map where the keys are greater or equal to startKey.
Throws
ClassCastException if the class of the start key is inappropriate for this sorted map.
NullPointerException if the start key is null and this sorted map does not support null keys.
IllegalArgumentException if this map itself a sorted map over a range of another map and the specified key is outside of its range.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.