Synchronized Map In Java
Chapter:
Collections
Last Updated:
21-06-2016 20:53:02 UTC
Program:
/* ............... START ............... */
package Collections;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class JavaSynchronizedMapExample {
public static void main(String a[]){
Map<String,String> map = new HashMap<String,String>();
Map<String,String> synchronizedMap = Collections.synchronizedMap(map);
System.out.println("Synchronized Map has been created.");
}
}
/* ............... END ............... */
Output
Synchronized list has been created.
Notes:
-
The Map is not synchornized (not thread-safe).
- Collections.synchronizedMap() method returns a synchronized (thread-safe) map backed by the specified map.
Tags
Synchronized Map, Java, Collection