Javatpoint Logo
Javatpoint Logo

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

Test it Now

Output:

Synchronized map is :{1=Rahul, 3=Mohan, 4=Karan}

Example 2

Test it Now

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

Test it Now

Output:

10000





Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA