- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference between HashTable and HashMap in Java
Following are the notable differences between HashTable and HashMap classes in Java.
HashTable | HashMap | |
---|---|---|
Synchronized | HashTable is synchronized. | HashMap is not synchronized. |
Thread Safe | HashTable is thread safe. | HashMap is not thread safe. |
Null objects | HashTable does not allows null keys or null values. | HashMap allows one null key and multiple null values. |
Performance | HashTable is faster. | HashMap is slower than HashTable. |
Since Java Version | 1.2 | 1.5 |
Example
import java.util.HashMap; import java.util.Hashtable; import java.util.Map; public class Tester { public static void main(String args[]) { Map<String, String> map = new HashMap<String, String>(); map.put("1", "One"); map.put("2", "Two"); map.put("3", "Three"); map.put("5", "Five"); map.put("6", "Six"); System.out.println("HashMap: " + map); Map<String, String> map1 = new Hashtable<String, String>(); map1.put("1", "One"); map1.put("2", "Two"); map1.put("3", "Three"); map1.put("5", "Five"); map1.put("6", "Six"); System.out.println("HashTable: " + map1); } }
Output
HashMap: {1 = One, 2 = Two, 3 = Three, 5 = Five, 6 = Six} HashTable: {6 = Six, 5 = Five, 3 = Three, 2 = Two, 1 = One}
- Related Articles
- Difference between HashMap and HashTable in Java.
- Differences between HashMap and Hashtable in Java
- What is the differences between HashMap and HashTable in Java
- Difference between HashTable and ConcurrentHashMap in Java
- Difference between HashMap and ConcurrentHashMap in Java
- Difference between HashMap and HashSet in Java.
- Difference between EnumMap and HashMap in Java
- Difference Between HashMap and TreeMap in Java
- Difference Between HashMap and LinkedHashMap in Java
- Difference between TreeMap, HashMap, and LinkedHashMap in Java
- Difference between TreeMap, HashMap and LinkedHashMap in Java programming
- Difference between Concurrent hash map and Synchronized hashmap in Java
- Difference between HashMap and ConcurrentHashMap
- Difference between Map and HashMap
- Difference between Dictionary and Hashtable in C#

Advertisements