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