Java Programming - Objects and Collections - Discussion


Which collection class allows you to access its elements by associating a key with an element's value, and provides synchronization?

[A]. java.util.SortedMap
[B]. java.util.TreeMap
[C]. java.util.TreeSet
[D]. java.util.Hashtable

Answer: Option D


Hashtable is the only class listed that provides synchronized methods. If you need synchronization great; otherwise, use HashMap, it's faster.

Sanjeev Mishra said: (Sep 2, 2012)  
Please give me the difference between Hashtable and HashMap related to above question?

Aaru said: (Aug 21, 2013)  
What is synchronization in this?

Rajesh Kushwaha said: (Sep 22, 2014)  
Hashtable is synchronised but HashMap is not synchronised.

So Hashtable is correct answer.

Mac said: (May 10, 2015)  
@Sanjeev Mishra.

It means that the access to the underlying collection (add, get, set, put, remove, etc.) is all synchronized. It cannot take place simultaneously and finally its Thread Safe.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.