TreeMap Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
A Red-Black tree based NavigableMap
implementation.
[Android.Runtime.Register("java/util/TreeMap", DoNotGenerateAcw=true)]
[Java.Interop.JavaTypeParameters(new System.String[] { "K", "V" })]
public class TreeMap : Java.Util.AbstractMap, IDisposable, Java.Interop.IJavaPeerable, Java.IO.ISerializable, Java.Lang.ICloneable, Java.Util.INavigableMap
[<Android.Runtime.Register("java/util/TreeMap", DoNotGenerateAcw=true)>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "K", "V" })>]
type TreeMap = class
inherit AbstractMap
interface ISerializable
interface IJavaObject
interface IDisposable
interface IJavaPeerable
interface ICloneable
interface INavigableMap
interface ISortedMap
interface IMap
- Inheritance
- Attributes
- Implements
Remarks
A Red-Black tree based NavigableMap
implementation. The map is sorted according to the Comparable natural ordering of its keys, or by a Comparator
provided at map creation time, depending on which constructor is used.
This implementation provides guaranteed log(n) time cost for the containsKey
, get
, put
and remove
operations. Algorithms are adaptations of those in Cormen, Leiserson, and Rivest's <em>Introduction to Algorithms</em>.
Note that the ordering maintained by a tree map, like any sorted map, and whether or not an explicit comparator is provided, must be <em>consistent with equals
</em> if this sorted map is to correctly implement the Map
interface. (See Comparable
or Comparator
for a precise definition of <em>consistent with equals</em>.) This is so because the Map
interface is defined in terms of the equals
operation, but a sorted map performs all key comparisons using its compareTo
(or compare
) method, so two keys that are deemed equal by this method are, from the standpoint of the sorted map, equal. The behavior of a sorted map <em>is</em> well-defined even if its ordering is inconsistent with equals
; it just fails to obey the general contract of the Map
interface.
<strong>Note that this implementation is not synchronized.</strong> If multiple threads access a map concurrently, and at least one of the threads modifies the map structurally, it <em>must</em> be synchronized externally. (A structural modification is any operation that adds or deletes one or more mappings; merely changing the value associated with an existing key is not a structural modification.) This is typically accomplished by synchronizing on some object that naturally encapsulates the map. If no such object exists, the map should be "wrapped" using the Collections#synchronizedSortedMap Collections.synchronizedSortedMap
method. This is best done at creation time, to prevent accidental unsynchronized access to the map:
SortedMap m = Collections.synchronizedSortedMap(new TreeMap(...));
The iterators returned by the iterator
method of the collections returned by all of this class's "collection view methods" are <em>fail-fast</em>: if the map is structurally modified at any time after the iterator is created, in any way except through the iterator's own remove
method, the iterator will throw a ConcurrentModificationException
. Thus, in the face of concurrent modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future.
Note that the fail-fast behavior of an iterator cannot be guaranteed as it is, generally speaking, impossible to make any hard guarantees in the presence of unsynchronized concurrent modification. Fail-fast iterators throw ConcurrentModificationException
on a best-effort basis. Therefore, it would be wrong to write a program that depended on this exception for its correctness: <em>the fail-fast behavior of iterators should be used only to detect bugs.</em>
All Map.Entry
pairs returned by methods in this class and its views represent snapshots of mappings at the time they were produced. They do <strong>not</strong> support the Entry.setValue
method. (Note however that it is possible to change mappings in the associated map using put
.)
This class is a member of the Java Collections Framework.
Added in 1.2.
Java documentation for java.util.TreeMap
.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Constructors
TreeMap() |
Constructs a new, empty tree map, using the natural ordering of its keys. |
TreeMap(IComparator) |
Constructs a new, empty tree map, ordered according to the given comparator. |
TreeMap(IDictionary) |
Constructs a new tree map containing the same mappings as the given map, ordered according to the <em>natural ordering</em> of its keys. |
TreeMap(IntPtr, JniHandleOwnership) |
A constructor used when creating managed representations of JNI objects; called by the runtime. |
Properties
Class |
Returns the runtime class of this |
Handle |
The handle to the underlying Android instance. (Inherited from Object) |
IsEmpty |
To be added (Inherited from AbstractMap) |
JniIdentityHashCode | (Inherited from Object) |
JniPeerMembers | |
PeerReference | (Inherited from Object) |
ThresholdClass |
This API supports the Mono for Android infrastructure and is not intended to be used directly from your code. |
ThresholdType |
This API supports the Mono for Android infrastructure and is not intended to be used directly from your code. |
Methods
CeilingEntry(Object) | |
CeilingKey(Object) |
Added in 1. |
Clear() |
To be added (Inherited from AbstractMap) |
Clone() |
Returns a shallow copy of this |
Comparator() |
Returns the comparator used to compare keys in this sorted map, or null if the natural ordering is in use. |
ContainsKey(Object) |
To be added (Inherited from AbstractMap) |
ContainsValue(Object) |
To be added (Inherited from AbstractMap) |
DescendingKeySet() |
Added in 1. |
DescendingMap() |
Added in 1. |
Dispose() | (Inherited from Object) |
Dispose(Boolean) | (Inherited from Object) |
EntrySet() |
Returns a |
Equals(Object) |
Indicates whether some other object is "equal to" this one. (Inherited from Object) |
FirstEntry() |
Returns a key-value mapping associated with the least
key in this map, or |
FirstKey() |
Returns the least key in this sorted map. |
FloorEntry(Object) | |
FloorKey(Object) |
Added in 1. |
ForEach(IBiConsumer) | |
Get(Object) |
To be added (Inherited from AbstractMap) |
GetHashCode() |
Returns a hash code value for the object. (Inherited from Object) |
HeadMap(Object, Boolean) |
Added in 1. |
HeadMap(Object) | |
HigherEntry(Object) | |
HigherKey(Object) |
Added in 1. |
JavaFinalize() |
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. (Inherited from Object) |
KeySet() |
To be added (Inherited from AbstractMap) |
LastEntry() |
Returns a key-value mapping associated with the greatest
key in this map, or |
LastKey() |
Returns the greatest key in this sorted map. |
LowerEntry(Object) | |
LowerKey(Object) |
Added in 1. |
NavigableKeySet() |
Added in 1. |
Notify() |
Wakes up a single thread that is waiting on this object's monitor. (Inherited from Object) |
NotifyAll() |
Wakes up all threads that are waiting on this object's monitor. (Inherited from Object) |
PollFirstEntry() |
Removes and returns a key-value mapping associated with
the least key in this map, or |
PollLastEntry() |
Removes and returns a key-value mapping associated with
the greatest key in this map, or |
Put(Object, Object) |
To be added (Inherited from AbstractMap) |
PutAll(IDictionary) |
To be added (Inherited from AbstractMap) |
Remove(Object) |
To be added (Inherited from AbstractMap) |
Replace(Object, Object, Object) | |
Replace(Object, Object) | |
ReplaceAll(IBiFunction) | |
SetHandle(IntPtr, JniHandleOwnership) |
Sets the Handle property. (Inherited from Object) |
Size() |
To be added (Inherited from AbstractMap) |
SubMap(Object, Boolean, Object, Boolean) |
Added in 1. |
SubMap(Object, Object) | |
TailMap(Object, Boolean) |
Added in 1. |
TailMap(Object) | |
ToArray<T>() | (Inherited from Object) |
ToString() |
Returns a string representation of the object. (Inherited from Object) |
UnregisterFromRuntime() | (Inherited from Object) |
Values() |
To be added (Inherited from AbstractMap) |
Wait() |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>. (Inherited from Object) |
Wait(Int64, Int32) |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed. (Inherited from Object) |
Wait(Int64) |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed. (Inherited from Object) |
Explicit Interface Implementations
IJavaPeerable.Disposed() | (Inherited from Object) |
IJavaPeerable.DisposeUnlessReferenced() | (Inherited from Object) |
IJavaPeerable.Finalized() | (Inherited from Object) |
IJavaPeerable.JniManagedPeerState | (Inherited from Object) |
IJavaPeerable.SetJniIdentityHashCode(Int32) | (Inherited from Object) |
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) | (Inherited from Object) |
IJavaPeerable.SetPeerReference(JniObjectReference) | (Inherited from Object) |
Extension Methods
JavaCast<TResult>(IJavaObject) |
Performs an Android runtime-checked type conversion. |
JavaCast<TResult>(IJavaObject) | |
GetJniTypeName(IJavaPeerable) |