Re: difference between hashtable and hashMap ?
On 8/24/2014 2:03 AM, Rishipal Singh wrote:
what is difference between hashtable and hashMap ;
please explain with examples
If by "hashtable" you actually mean "HashTable", the latter is
probably the class "java.util.HashTable", a key-to-value map that
has been around since the very first versions of Java.
If by "hashMap" you actually mean "HashMap", the latter is
probably the class "java.util.HashMap", another key-to-value map
of more recent (Java 1.2, 1998) vintage.
Both are used in similar ways: You can add and remove key/value
pairs, offer a key and retrieve its associated value, change the
value associated with a key, iterate over all the keys, all the
values, or all the pairs, and so on. There are differences in
detail, most notably that HashTable methods are "synchronized"
while HashMap methods are not, but the two are broadly similar.
Prefer HashMap unless you have a compelling reason to choose
HashTable instead -- for example, if you're using an old API that
specifically requires HashTable, you have no choice and must use
one. But for new work, choose HashMap instead. Also, if your
classes expose a key/value map to their clients, prefer to expose
it as a Map even if you actually use HashMap internally; that way,
you can change to a different kind of map later on (if that seems
a good idea) without disturbing your clients.
--
esosman@comcast-dot-net.invalid