Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #29874
| From | Brixomatic <brixomatic@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: difference between hashtable and hashMap ? |
| Date | 2014-08-30 14:07 +0200 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <MPG.2e6bdce2b6dd821989686@news.aioe.org> (permalink) |
| References | <a32f3a08-49ca-48dc-88c6-1b58aacbf1e5@googlegroups.com> |
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]
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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