Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #29830 > unrolled thread
| Started by | Rishipal Singh <95rishipal@gmail.com> |
|---|---|
| First post | 2014-08-23 23:03 -0700 |
| Last post | 2014-08-31 09:42 +0200 |
| Articles | 19 — 10 participants |
Back to article view | Back to comp.lang.java.programmer
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
| From | Rishipal Singh <95rishipal@gmail.com> |
|---|---|
| Date | 2014-08-23 23:03 -0700 |
| Subject | difference between hashtable and hashMap ? |
| Message-ID | <a32f3a08-49ca-48dc-88c6-1b58aacbf1e5@googlegroups.com> |
what is difference between hashtable and hashMap ; please explain with examples
[toc] | [next] | [standalone]
| From | Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> |
|---|---|
| Date | 2014-08-24 08:09 +0000 |
| Message-ID | <slrnlvj7dn.fp3.avl@login.logic.tuwien.ac.at> |
| In reply to | #29830 |
Rishipal Singh <95rishipal@gmail.com> wrote: > what is difference between hashtable and hashMap ; > please explain with examples HashTable is OLD - don't use it for new code. (same as Enumeration and Vector)
[toc] | [prev] | [next] | [standalone]
| From | Josip Almasi <joe@vrspace.org> |
|---|---|
| Date | 2014-08-24 11:41 +0200 |
| Message-ID | <ltcbve$789$1@gregory.bnet.hr> |
| In reply to | #29830 |
On 08/24/2014 08:03 AM, Rishipal Singh wrote: > what is difference between hashtable and hashMap ; > please explain with examples Hashtable is synchronized, and HashMap is not. However, Hashtable's iterators are not synchronized, meaning it's rather useless - use ConcurrentHashMap instead. Google ConcurrentHashMap examples. Regards...
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2014-08-24 08:13 -0400 |
| Message-ID | <ltcksl$jpd$1@dont-email.me> |
| In reply to | #29830 |
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
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2014-08-24 08:48 -0400 |
| Message-ID | <53f9df0c$0$299$14726298@news.sunsite.dk> |
| In reply to | #29835 |
On 8/24/2014 8:13 AM, Eric Sosman wrote: > 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", Never heard of that one ... > a key-to-value map that > has been around since the very first versions of Java. If you ignore case then there is such a class ... :-) Arne
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2014-08-24 09:28 -0400 |
| Message-ID | <ltcpav$gcv$1@dont-email.me> |
| In reply to | #29836 |
On 8/24/2014 8:48 AM, Arne Vajhøj wrote:
> On 8/24/2014 8:13 AM, Eric Sosman wrote:
>> 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",
>
> Never heard of that one ...
<facepalm>"java.util.Hashtable", of course.</facepalm>
--
esosman@comcast-dot-net.invalid
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2014-08-24 14:31 -0400 |
| Message-ID | <53fa2fa3$0$292$14726298@news.sunsite.dk> |
| In reply to | #29838 |
On 8/24/2014 9:28 AM, Eric Sosman wrote: > On 8/24/2014 8:48 AM, Arne Vajhøj wrote: >> On 8/24/2014 8:13 AM, Eric Sosman wrote: >>> 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", >> >> Never heard of that one ... > > <facepalm>"java.util.Hashtable", of course.</facepalm> Given that hash and table are two words (in English) then I guess it should have been with capital T, but ... Arne
[toc] | [prev] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2014-08-24 22:35 -0700 |
| Message-ID | <tnilv95i5l2ll1ctmehn2dfjkpchno3j1k@4ax.com> |
| In reply to | #29840 |
On Sun, 24 Aug 2014 14:31:51 -0400, Arne Vajhøj <arne@vajhoej.dk> wrote, quoted or indirectly quoted someone who said : > >Given that hash and table are two words (in English) then >I guess it should have been with capital T, but ... This business of capital letters in the middle of words was unknown until WordPerfect did it. Now it is everywhere. -- Roedy Green Canadian Mind Products http://mindprod.com Errors using inadequate data are much less than those using no data at all. ~ Charles Babbage (born: 1791-12-26 died: 1871-10-18 at age: 79)
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2014-08-25 20:41 -0400 |
| Message-ID | <53fbd7b9$0$302$14726298@news.sunsite.dk> |
| In reply to | #29848 |
On 8/25/2014 1:35 AM, Roedy Green wrote: > On Sun, 24 Aug 2014 14:31:51 -0400, Arne Vajhøj <arne@vajhoej.dk> > wrote, quoted or indirectly quoted someone who said : >> Given that hash and table are two words (in English) then >> I guess it should have been with capital T, but ... > > This business of capital letters in the middle of words was unknown > until WordPerfect did it. Now it is everywhere. I would tend to consider Hashtable/HashTable for two words with no space in between. Where traditional Java convention is to capitalize both words. Arne
[toc] | [prev] | [next] | [standalone]
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Date | 2014-08-26 04:21 -0400 |
| Message-ID | <lthg3g$v4p$1@dont-email.me> |
| In reply to | #29848 |
On 08/25/2014 01:35 AM, Roedy Green wrote: > On Sun, 24 Aug 2014 14:31:51 -0400, Arne Vajhøj <arne@vajhoej.dk> > wrote, quoted or indirectly quoted someone who said : > >> >> Given that hash and table are two words (in English) then >> I guess it should have been with capital T, but ... > > This business of capital letters in the middle of words was unknown > until WordPerfect did it. Now it is everywhere. > This article is asking for improvements. <http://en.wikipedia.org/wiki/CamelCase#Computer_programming>
[toc] | [prev] | [next] | [standalone]
| From | "Qu0ll" <Qu0llSixFour@gmail.com> |
|---|---|
| Date | 2014-08-31 10:27 +1000 |
| Message-ID | <lttq76$o38$1@speranza.aioe.org> |
| In reply to | #29840 |
"Arne Vajhøj" wrote in message news:53fa2fa3$0$292$14726298@news.sunsite.dk... > Given that hash and table are two words (in English) then > I guess it should have been with capital T, but ... I have always been fascinated by the naming of the System.out.println() method. What naming rules does it follow other than "copy from C/C++ and Pascal"? -- And loving it, -Qu0ll (Rare, not extinct) _________________________________________________ Qu0llSixFour@gmail.com [Replace the "SixFour" with numbers to email me]
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2014-09-07 22:10 -0400 |
| Message-ID | <540d102e$0$298$14726298@news.sunsite.dk> |
| In reply to | #29876 |
On 8/30/2014 8:27 PM, Qu0ll wrote: > "Arne Vajhøj" wrote in message > news:53fa2fa3$0$292$14726298@news.sunsite.dk... > >> Given that hash and table are two words (in English) then >> I guess it should have been with capital T, but ... > > I have always been fascinated by the naming of the System.out.println() > method. > > What naming rules does it follow other than "copy from C/C++ and Pascal"? None that I can think of. It should have been printLine. But I think it is a fair guess that this method may have been implemented way before anybody had started thinking about coding conventions. Arne
[toc] | [prev] | [next] | [standalone]
| From | "Qu0ll" <Qu0llSixFour@gmail.com> |
|---|---|
| Date | 2014-09-08 13:41 +1000 |
| Message-ID | <luj8hu$snc$1@speranza.aioe.org> |
| In reply to | #29930 |
"Arne Vajhøj" wrote in message news:540d102e$0$298$14726298@news.sunsite.dk... >> I have always been fascinated by the naming of the System.out.println() >> method. >> >> What naming rules does it follow other than "copy from C/C++ and Pascal"? > > None that I can think of. > >It should have been printLine. I totally disagree - there's no "printing" of any kind happening here. My choice would be "outputLine". > But I think it is a fair guess that this method may have been > implemented way before anybody had started thinking about > coding conventions. Probably, or at least when several different sets of conventions were floating around. -- And loving it, -Qu0ll (Rare, not extinct) _________________________________________________ Qu0llSixFour@gmail.com [Replace the "SixFour" with numbers to email me]
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2014-08-24 08:52 -0400 |
| Message-ID | <53f9e02e$0$299$14726298@news.sunsite.dk> |
| In reply to | #29830 |
On 8/24/2014 2:03 AM, Rishipal Singh wrote: > what is difference between hashtable and hashMap ; > please explain with examples Hashtable - old, should not be used in new code if you can avoid it HashMap - new, what you should use today The reason for the two classes are historical/evolutionary. Technically the main difference is that the methods in Hashtable are synchronized while the methods in HashMap are not. The benefit of single method calls being synchronized is zero in single threaded context and often very small in a multi-threaded context. And it do come with some overhead. But in my opinion the false feeling of safety is a bigger problem than the actual overhead. Arne
[toc] | [prev] | [next] | [standalone]
| From | Wayne <nospam@all.invalid> |
|---|---|
| Date | 2014-08-24 18:04 -0400 |
| Subject | OT: Re: difference between hashtable and hashMap ? |
| Message-ID | <yjtKv.73388$O13.29807@fx17.iad> |
| In reply to | #29837 |
On 8/24/2014 8:52 AM, Arne Vajhøj wrote: > On 8/24/2014 2:03 AM, Rishipal Singh wrote: >> what is difference between hashtable and hashMap ; >> please explain with examples > > Hashtable - old, should not be used in new code if you can avoid it > HashMap - new, what you should use today > > The reason for the two classes are historical/evolutionary. > > Technically the main difference is that the methods in Hashtable > are synchronized while the methods in HashMap are not. > > The benefit of single method calls being synchronized is > zero in single threaded context and often very small in > a multi-threaded context. And it do come with some overhead. > But in my opinion the false feeling of safety is a bigger problem > than the actual overhead. > > Arne > > There is also synchronizedMap (created with java.util.Collections). But if you care about current access, you are probably better of with java.util.concurrent.ConcurrentHashMap. -- Wayne
[toc] | [prev] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2014-08-24 22:36 -0700 |
| Message-ID | <bqilv9h6f4qg8jsd9gcjqotq773i0k5lbj@4ax.com> |
| In reply to | #29830 |
On Sat, 23 Aug 2014 23:03:26 -0700 (PDT), Rishipal Singh <95rishipal@gmail.com> wrote, quoted or indirectly quoted someone who said : >what is difference between hashtable and hashMap ; > please explain with examples see http://mindprod.com/jgloss/hashtable.html http://mindprod.com/jgloss/hashmap.html This smells like homework. http://mindprod.com/jgloss/homework.html -- Roedy Green Canadian Mind Products http://mindprod.com Errors using inadequate data are much less than those using no data at all. ~ Charles Babbage (born: 1791-12-26 died: 1871-10-18 at age: 79)
[toc] | [prev] | [next] | [standalone]
| From | Brixomatic <brixomatic@yahoo.com> |
|---|---|
| Date | 2014-08-30 14:07 +0200 |
| Message-ID | <MPG.2e6bdce2b6dd821989686@news.aioe.org> |
| In reply to | #29830 |
In article <a32f3a08-49ca-48dc-88c6-1b58aacbf1e5@googlegroups.com>, Rishipal Singh (95rishipal@gmail.com) says... > > what is difference between hashtable and hashMap ; > please explain with examples The HashTable is synchronized (not including the iterator), which is not needed usually. If you need synchronization you can use Map<K,V> synchMap = Collections.sychronizedMap(unsynchMap); to wrap any map in a decorator/proxy map that adds synchronization (and is backed by the original you provided). One might think that with this the original HashTable is not needed anymore, but that's not entirely true. The major advantage of java.util.HashTable to java.util.HashMap is that you can have a custom load factor with the HashTable, which might help you in improving the behavior in cases where you need to sacrifice some speed in favor of space. An increased load factor will slow the table down as hash collisions get more likely, but the table will not grow in size that fast, OTOH a lower load factor will make the table grow faster to provide more space for less hash collisions. Usually the load factor is a non issue and synchronization is not needed, which means that HashMap should be your standard map implementation. In rare cases, if you really need to fine tune a map, wi ch means you need some special property that HashMap doesn't supply (altering the load factor, iterating in the order in that the elements were added, removing duplicates and/or ordering according to a custom comparator stragety, lightly multithreaded access, heavy multithreaded access, values that become free for garbage collection if their keys are not referenced anymore, etc.) you might have a look at other Map implementations, such as HashTable, ConcurrentHashMap, TreeMap or WeakHashMap. But you should really know what you're doing there, which means (regarding your novice question), probably not yet. Kind regards, Wanja -- ..Alesi's problem was that the back of the car was jumping up and down dangerously - and I can assure you from having been teammate to Jean Alesi and knowing what kind of cars that he can pull up with, when Jean Alesi says that a car is dangerous - it is. [Jonathan Palmer]
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2014-08-30 16:39 -0400 |
| Message-ID | <lttcqr$1l4$1@dont-email.me> |
| In reply to | #29874 |
On 8/30/2014 8:07 AM, Brixomatic wrote:
> In article <a32f3a08-49ca-48dc-88c6-1b58aacbf1e5@googlegroups.com>,
> Rishipal Singh (95rishipal@gmail.com) says...
>>
>> what is difference between hashtable and hashMap ;
>> please explain with examples
>
> The HashTable is synchronized (not including the iterator), which is not
> needed usually.
It's "Hashtable", not "HashTable" (I made the same mistake, so
I can sympathize ...)
>[...]
> The major advantage of java.util.HashTable to java.util.HashMap is that
> you can have a custom load factor with the HashTable, which might help
> you in improving the behavior in cases where you need to sacrifice some
> speed in favor of space.
Um, er, why do you think HashMap's load factor can't be customized?
Is the HashMap(int,float) constructor lying to us?
--
esosman@comcast-dot-net.invalid
[toc] | [prev] | [next] | [standalone]
| From | Brixomatic <brixomatic@yahoo.com> |
|---|---|
| Date | 2014-08-31 09:42 +0200 |
| Message-ID | <MPG.2e6cf06a4d01af02989687@news.aioe.org> |
| In reply to | #29875 |
In article <lttcqr$1l4$1@dont-email.me>, Eric Sosman (esosman@comcast- dot-net.invalid) says... > Um, er, why do you think HashMap's load factor can't be customized? > Is the HashMap(int,float) constructor lying to us? Dang! How could I miss that? My bad. Kind regards, Wanja -- ..Alesi's problem was that the back of the car was jumping up and down dangerously - and I can assure you from having been teammate to Jean Alesi and knowing what kind of cars that he can pull up with, when Jean Alesi says that a car is dangerous - it is. [Jonathan Palmer]
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web