Collections.synchronizedList(List): This method is available in java.util.Collections class of Java.
Syntax:
<E> List<Integer> java.util.Collections.synchronizedList(List<E> list)
This method takes one argument. This method returns a synchronized (thread-safe) list backed by the specified list.
Parameters: One parameter is required for this method.
list: the list to be "wrapped" in a synchronized list.
Returns: a synchronized view of the specified list.
Exceptions: NA
Approach
Java
import java.util.ArrayList;import java.util.Collections;import java.util.List;public class CollectionssynchronizedList {public static void main(String[] args) {List<Integer> arrlist = new ArrayList<Integer>();arrlist.add(12);arrlist.add(56);arrlist.add(899);arrlist.add(65);arrlist.add(5);System.out.println(Collections.synchronizedList(arrlist));}}
Output:
[12, 56, 899, 65, 5]
No comments:
Post a Comment