Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4e599e8

Browse files
Update HashTable_vs_HashMap.md
1 parent cf1ba01 commit 4e599e8

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed
Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,42 @@
1-
``` HashTable v/s HashMap
1+
### HashTable v/s HashMap
2+
23
Before this, I would suggest to go through the topic Iterator V/S Enumeration here.
34

45
There are some significant factors that makes both of these data structures different
56

6-
1. Synchronization or Thread Safety
7-
- This is the most important difference between the two.
8-
- Hash tables are synchronized and thread safe whereas Hash maps are not.
7+
**1. Synchronization or Thread Safety**
8+
- This is the most important difference between the two.
9+
- Hash tables are synchronized and thread safe whereas Hash maps are not.
910

10-
2. Null keys and Null values
11-
- HashMap allows one null key and multiple null values, whereas hash table doesn't allow neither null values not null keys.
11+
**2. Null keys and Null values**
12+
- HashMap allows one null key and multiple null values, whereas hash table doesn't allow neither null values not null keys.
1213

13-
3. Iterating the Values
14-
- Values in hash map are iterated using an iterator, whereas in hash table values are iterated using enumerator.
15-
- Only Vector other then hash table uses enumerator to iterate through elements.
14+
**3. Iterating the Values**
15+
- Values in hash map are iterated using an iterator, whereas in hash table values are iterated using enumerator.
16+
- Only Vector other then hash table uses enumerator to iterate through elements.
1617

17-
4. Fail Fast Iterator
18-
- Iterator in hash map is fail fast iterator, whereas enumerator for hash table is not.
19-
- If hash table is structurally modified at any time after the iterator is created other then iterators own remove method, then it will throw Concurrent Modification exception.
20-
- Structural modification means adding or removing elements from the collection.
18+
**4. Fail Fast Iterator**
19+
- Iterator in hash map is fail fast iterator, whereas enumerator for hash table is not.
20+
- If hash table is structurally modified at any time after the iterator is created other then iterators own remove method, then it will throw Concurrent Modification exception.
21+
- Structural modification means adding or removing elements from the collection.
2122

22-
5. Super class and Legacy
23-
- HashTable is a subclass of Dictionary, which is now obsolete from JDK 1.7
23+
**5. Super class and Legacy**
24+
- HashTable is a subclass of Dictionary, which is now obsolete from JDK 1.7
2425

25-
6. Performance
26-
- HashMap is much faster and uses less memory because it is not synchronized.
26+
**6. Performance**
27+
- HashMap is much faster and uses less memory because it is not synchronized.
2728

28-
Similarities :
29-
1. Order of elements
30-
- Cannot be guaranteed, because both of these work based on the hashing logic. use Linked Hash map for that
31-
2. Both of them comes from Map interface.
32-
3. Both provides constant time for performance for put and get methods, assuming that objects are distributed uniformly.
33-
4. Both works on the principle of hashing
29+
**Similarities :**
30+
```
31+
- Order of elements cannot be guaranteed, because both of these work based on the hashing logic. use Linked Hash map for that
32+
- Both of them comes from Map interface.
33+
- Both provides constant time for performance for put and get methods, assuming that objects are distributed uniformly.
34+
- Both works on the principle of hashing
35+
```
3436

35-
When to use?
37+
**When to use?**
38+
```
3639
Avoid using HashTable, as they are obsolete now, ConcurrentHashMap has replaced it.
3740
Single threaded apps - use HashMap
38-
41+
```
42+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /