There are several differences between HashMap
and Hashtable
in Java:
Hashtable
is synchronized, whereasHashMap
is not. This makesHashMap
better for non-threaded applications, as unsynchronized Objects typically perform better than synchronized ones.Hashtable
does not allownull
keys or values.HashMap
allows onenull
key and any number ofnull
values.- One of HashMap’s subclasses is
LinkedHashMap
, so in the event that you’d want predictable iteration order (which is insertion order by default), you could easily swap out theHashMap
for aLinkedHashMap
. This wouldn’t be as easy if you were usingHashtable
.
Since synchronization is not an issue for you, I’d recommend HashMap
. If synchronization becomes an issue, you may also look at ConcurrentHashMap
.
Related Posts:
- Difference between HashSet and HashMap?
- Java Ordered Map
- Hashtable, HashMap, HashSet , hash table concept in Java collection framework
- Easiest way to convert a List to a Set in Java
- ConcurrentHashMap and Hashtable in Java
- Any implementation of Ordered Set in Java?
- Any implementation of Ordered Set in Java?
- How to use Collections.sort() in Java?
- When to use LinkedList over ArrayList in Java?
- Difference between Arrays.asList(array) and new ArrayList
(Arrays.asList(array)) - Is a Python dictionary an example of a hash table?
- Initialization of an ArrayList in one line
- How to sort an ArrayList?
- Exception in thread “main” java.lang.StackOverflowError
- Exception in thread “main” java.lang.StackOverflowError
- Iterate through a HashMap [duplicate]
- C# Java HashMap equivalent
- C# Java HashMap equivalent
- Iterate through a HashMap [duplicate]
- Why is there no SortedList in Java?
- What is the significance of load factor in HashMap?
- How to update a value, given a key in a hashmap?
- Collision resolution in Java HashMap
- How to convert List
to int[] in Java? - Difference between HashMap and Map in Java..?
- Printing HashMap In Java
- Java Hashmap: How to get key from value?
- How to convert int[] into List
in Java? - Sorting HashMap by values
- How do I efficiently iterate over each entry in a Java Map?
- How to sort Map values by key in Java?
- HashSet vs. ArrayList
- FIFO based Queue implementations?
- HashMap get/put complexity
- What is a hash map in programming and where can it be used
- Create a List of primitive int?
- What is the difference between the HashMap and Map objects in Java?
- How to convert int[] to Integer[] in Java?
- Change priorityQueue to max priorityqueue
- Collections.emptyMap() vs new HashMap()
- “Cannot create generic array of ..” – how to create an Array of Map
? - Sort a Map
by values - Good Hash Function for Strings
- Most efficient way to increment a Map value in Java
- What is a hash function in java?
- Printing a java map Map
– How? - Why is a ConcurrentModificationException thrown and how to debug it
- How to sort a HashSet?
- Union or intersection of Java Sets
- What is a hash function in java?
- Map of maps – how to keep the inner maps as maps?
- toring and Retrieving ArrayList values from hashmap
- Java associative-array
- What does Java option -Xmx stand for? [duplicate]
- How do I convert a String to an int in Java?
- What does Java option -Xmx stand for? [duplicate]
- Is there an invisible character that is not regarded as whitespace?
- Problem with gif with transparent background
- Finding white rectangle in an image
- 1000 * 60 * 60 * 24 * 30 results in a negative number [duplicate]
- How to convert nanoseconds to seconds using the TimeUnit enum?
- Search for words with telephone numbers from 2-3-4 tree
- How to do associative array/hashing in JavaScript
- Using or ‘|’ in regex [duplicate]
- How to format strings in Java
- What is the difference between x86 and x64
- && (AND) and || (OR) in IF statements
- How to use the toString method in Java?
- What is a NullPointerException, and how do I fix it?
- What exactly is Apache Camel?
- Unable to find valid certification path to requested target – error even after cert imported
- Unable to find valid certification path to requested target – error even after cert imported
- What is the equivalent of the C++ Pair
in Java? - Java – Convert integer to string [duplicate]
- Getting random numbers in Java [duplicate]
- What is an instance variable in Java?
- javac is not recognized as an internal or external command, operable program or batch file [closed]
- javac is not recognized as an internal or external command, operable program or batch file [closed]
- Java: “error: cannot find symbol”
- How does the Java ‘for each’ loop work?
- Which is the difference between Long.valueOf(0) and 0L in Java?
- What is a StackOverflowError?
- Use of “instanceof” in Java [duplicate]
- What is the best way to use a HashMap in C++?
- What is the best way to use a HashMap in C++?
- How to uninstall Eclipse?
- Is GNU’s Java Compiler (GCJ) dead? [closed]
- How does System.out.print() work?
- How do I “decompile” Java class files? [closed]
- How do I determine whether an array contains a particular value in Java?
- How to initialize an array in Java?
- How does the Java ‘for each’ loop work?
- Java 8 Iterable.forEach() vs foreach loop
- Initialize part of an array in java
- How can I solve Exception in thread “main” java.lang.NullPointerException error [duplicate]
- How to split a string in Java
- What does “Could not find or load main class” mean?
- What does “Could not find or load main class” mean?
- Why am I getting a NoClassDefFoundError in Java?
- How to avoid “ConcurrentModificationException” while removing elements from `ArrayList` while iterating it? [duplicate]