Creating a Hashtable in Java
Basic Declaration
Declare variables using the parent Map interface:
import java.util.Hashtable;
import java.util.Map;
// Map<KeyType, ValueType> map = new Hashtable<>();
Map<String, Integer> balances = new Hashtable<>();
Null Value Restriction Warning
[!WARNING] Hashtable does not allow null keys OR null values. Attempting to insert a null key or null value throws a
NullPointerExceptioninstantly.
Hashtable Constructors
- Default Constructor: Sets initial capacity to 11 and load factor to 0.75.
- Initial Capacity Constructor:
Back to HashTable Home: HashTable Index