Partager via


Collections.NewSetFromMap(IDictionary) Method

Definition

Returns a set backed by the specified map.

[Android.Runtime.Register("newSetFromMap", "(Ljava/util/Map;)Ljava/util/Set;", "")]
[Java.Interop.JavaTypeParameters(new System.String[] { "E" })]
public static System.Collections.ICollection NewSetFromMap (System.Collections.IDictionary map);
[<Android.Runtime.Register("newSetFromMap", "(Ljava/util/Map;)Ljava/util/Set;", "")>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "E" })>]
static member NewSetFromMap : System.Collections.IDictionary -> System.Collections.ICollection

Parameters

map
IDictionary

the backing map

Returns

the set backed by the map

Attributes

Remarks

Returns a set backed by the specified map. The resulting set displays the same ordering, concurrency, and performance characteristics as the backing map. In essence, this factory method provides a Set implementation corresponding to any Map implementation. There is no need to use this method on a Map implementation that already has a corresponding Set implementation (such as HashMap or TreeMap).

Each method invocation on the set returned by this method results in exactly one method invocation on the backing map or its keySet view, with one exception. The addAll method is implemented as a sequence of put invocations on the backing map.

The specified map must be empty at the time this method is invoked, and should not be accessed directly after this method returns. These conditions are ensured if the map is created empty, passed directly to this method, and no reference to the map is retained, as illustrated in the following code fragment:

Set&lt;Object&gt; weakHashSet = Collections.newSetFromMap(
                   new WeakHashMap&lt;Object, Boolean&gt;());

Added in 1.6.

Java documentation for java.util.Collections.newSetFromMap(java.util.Map<E, java.lang.Boolean>).

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.

Applies to