79
Java Collections synchronizedMap() Method
The synchronizedMap() method of Java Collections class is used to get a synchronized (thread-safe) map backed by the specified map.
Syntax
Following is the declaration of synchronizedMap() method:
Parameter
Parameter | Description | Required/Optional |
---|---|---|
m | It is the map which will be wrapped in a synchronized map. | Required |
Returns
The synchronizedMap() method returns a synchronized view of the specified Map.
Exceptions
NA
Example 1
Output:
Synchronized map is :{1=Rahul, 3=Mohan, 4=Karan}
Example 2
Output:
Map before Synchronized map: {1=1001, 2=1002, 3=1003, 4=1004, 5=1005} Synchronized map after remove(4, 1004):{1=1001, 2=1002, 3=1003, 5=1005}
Example 3
Output:
10000
Next TopicJava Collections Class