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
- “Javac” doesn’t work correctly on Windows 10
- How to uninstall Eclipse?
- Error parsing data org.json.JSONException: Value
- How to make a deep copy of Java ArrayList
- What does request.getParameter return?
- DB2 jdbc connection error Connection refused. ERRORCODE=-4499, SQLSTATE=08001
- Automated Python to Java translation
- EOFException – how to handle?
- How to fix array index out of bounds error?
- Getting Keyboard Input
- catDog string problem at Codingbat.com
- What is the difference between String.subString() and String.subSequence()
- Why Maven project is tied to J2SE-1.5 by default?
- How can I play sound in Java?
- IntelliJ: Error:java: error: release version 5 not supported
- error: unreported exception FileNotFoundException; must be caught or declared to be thrown
- implicit super constructor Person() is undefined. Must explicitly invoke another constructor?
- java.net.SocketTimeoutException: Read timed out under Tomcat
- How to resolve Error listenerStart when deploying web-app in Tomcat 5.5?
- package does not exist error!
- Missing method body, or declare abstract in Java
- java code is showing error. ( ‘;’,expected) [closed]
- How can I edit a .jar file?
- java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver Exception occurring. Why?
- Installing WindowBuilder on Eclipse Neon
- Java: Error creating a GZIPInputStream: Not in GZIP format
- Java: how to initialize String[]?
- Regular Expressions on Punctuation
- How to make a countdown timer in Java
- How to set String’s font size, style in Java using the Font class?
- Get an OutputStream into a String
- Difference between string object and string literal
- Best way to create enum of strings?
- Why use getters and setters/accessors?
- How to use a Do-while loop that continuously prompts a user?
- Eclipse IDE – Error: Build path specifies execution environment Java SE 1.7
- Why int[] a = new int[1] instead of just int a?
- ArithmeticException: “Non-terminating decimal expansion; no exact representable decimal result”
- What’s the console.log() of java?
- When to use a Map instead of a List in Java?
- How do I replace a character in a string in Java?
- What’s so special about 0x7f?
- Append a single character to a string or char array in java?
- Preventing a Java class from being instantiated and inherited
- Collision Detection between two images in Java
- What does .pack() do?
- String is immutable. What exactly is the meaning?