nirjari patel wrote:Hashtable can store key - value pairs, but it does not allow null values to be stored in it. (is this right ?)
Hashmap can store key-value pairs and also allows null values to be stored in it. (is this right ?)
You can find the answer quickly by writing a small program to try it out. Note that it's Hash
Map, not Hashmap (case is important in
Java).
Note that Hashtable is an old, legacy collection class. Since Java 1.2 (a LONG time ago) is has been more or less replaced by HashMap. Always use HashMap instead of Hashtable (unless there's a very special reason that you have to use Hashtable).
nirjari patel wrote:Does Hashset also store key-value pairs ? If yes, then whats the difference between Hashset and Hashtable ? or Hashset and Hashmap ? If it does not store key-value pairs and stores only objects, then whats the diffeence between Hashset and Arraylist ?
No, Hash
Set doesn't store key-value pairs.
A Set is a collection of unique objects that isn't ordered: you can think of it as a bag of things, the things are in no particular order, and each thing can be only in it once (no duplicates).
A List is a sequence of objects: it has a clear order, and it can contain objects that are equal (the same thing can appear more than once in a List).
HashSet is a particular implementation of a Set, and ArrayList is a particular implementation of a List. There are other implementations (for example TreeSet and LinkedList).