Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #29835

Re: difference between hashtable and hashMap ?

From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: difference between hashtable and hashMap ?
Date 2014-08-24 08:13 -0400
Organization A noiseless patient Spider
Message-ID <ltcksl$jpd$1@dont-email.me> (permalink)
References <a32f3a08-49ca-48dc-88c6-1b58aacbf1e5@googlegroups.com>

Show all headers | View raw


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

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

difference between hashtable and hashMap ? Rishipal Singh <95rishipal@gmail.com> - 2014-08-23 23:03 -0700
  Re: difference between hashtable and hashMap ? Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-08-24 08:09 +0000
  Re: difference between hashtable and hashMap ? Josip Almasi <joe@vrspace.org> - 2014-08-24 11:41 +0200
  Re: difference between hashtable and hashMap ? Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-24 08:13 -0400
    Re: difference between hashtable and hashMap ? Arne Vajhøj <arne@vajhoej.dk> - 2014-08-24 08:48 -0400
      Re: difference between hashtable and hashMap ? Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-24 09:28 -0400
        Re: difference between hashtable and hashMap ? Arne Vajhøj <arne@vajhoej.dk> - 2014-08-24 14:31 -0400
          Re: difference between hashtable and hashMap ? Roedy Green <see_website@mindprod.com.invalid> - 2014-08-24 22:35 -0700
            Re: difference between hashtable and hashMap ? Arne Vajhøj <arne@vajhoej.dk> - 2014-08-25 20:41 -0400
            Re: difference between hashtable and hashMap ? Jeff Higgins <jeff@invalid.invalid> - 2014-08-26 04:21 -0400
          Re: difference between hashtable and hashMap ? "Qu0ll" <Qu0llSixFour@gmail.com> - 2014-08-31 10:27 +1000
            Re: difference between hashtable and hashMap ? Arne Vajhøj <arne@vajhoej.dk> - 2014-09-07 22:10 -0400
              Re: difference between hashtable and hashMap ? "Qu0ll" <Qu0llSixFour@gmail.com> - 2014-09-08 13:41 +1000
  Re: difference between hashtable and hashMap ? Arne Vajhøj <arne@vajhoej.dk> - 2014-08-24 08:52 -0400
    OT: Re: difference between hashtable and hashMap ? Wayne <nospam@all.invalid> - 2014-08-24 18:04 -0400
  Re: difference between hashtable and hashMap ? Roedy Green <see_website@mindprod.com.invalid> - 2014-08-24 22:36 -0700
  Re: difference between hashtable and hashMap ? Brixomatic <brixomatic@yahoo.com> - 2014-08-30 14:07 +0200
    Re: difference between hashtable and hashMap ? Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-30 16:39 -0400
      Re: difference between hashtable and hashMap ? Brixomatic <brixomatic@yahoo.com> - 2014-08-31 09:42 +0200

csiph-web