Which of the following is a valid syntax to synchronize the HashMap?
A. Map m = hashMap.synchronizeMap();
B. HashMap map =hashMap.synchronizeMap();
C. Map m1 = Collections.synchronizedMap(hashMap);
D. Map m2 = Collection.synchronizeMap(hashMap);
Answer:C
Which of the following is a valid syntax to synchronize the HashMap?
A. Map m = hashMap.synchronizeMap(); B. HashMap map =hashMap.synchronizeMap(); C. Map m1 = Collections.synchronizedMap(hashMap); D. Map m2 = Collection.synchronizeMap(hashMap);
Explanation: By default, the HashMap class is a non-synchronized collection class. The need for synchronization is to perform thread-safe operations on the class. To synchronize the HashMap class explicitly, we should use the Collections.synchronizedMap(hashMap) method that returns a thread-safe map object.