Collections.SynchronizedSet(ICollection) Method
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.
Returns a synchronized (thread-safe) set backed by the specified set.
[Android.Runtime.Register("synchronizedSet", "(Ljava/util/Set;)Ljava/util/Set;", "")]
[Java.Interop.JavaTypeParameters(new System.String[] { "T" })]
public static System.Collections.ICollection SynchronizedSet (System.Collections.ICollection s);
[<Android.Runtime.Register("synchronizedSet", "(Ljava/util/Set;)Ljava/util/Set;", "")>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "T" })>]
static member SynchronizedSet : System.Collections.ICollection -> System.Collections.ICollection
Parameters
the set to be "wrapped" in a synchronized set.
Returns
a synchronized view of the specified set.
- Attributes
Remarks
Returns a synchronized (thread-safe) set backed by the specified set. In order to guarantee serial access, it is critical that <strong>all</strong> access to the backing set is accomplished through the returned set.
It is imperative that the user manually synchronize on the returned collection when traversing it via Iterator
, Spliterator
or Stream
:
Set s = Collections.synchronizedSet(new HashSet());
...
synchronized (s) {
Iterator i = s.iterator(); // Must be in the synchronized block
while (i.hasNext())
foo(i.next());
}
Failure to follow this advice may result in non-deterministic behavior.
The returned set will be serializable if the specified set is serializable.
Java documentation for java.util.Collections.synchronizedSet(java.util.Set<T>)
.
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.