On this page
  1. Hashtable
  2. Import
  3. Signature & Overview
  4. Notes & Pitfalls
  5. Example

Hashtable

Prev: `Vector` | Up: java.util | Next: java.util.stream
Rel: ConcurrentHashMap, java.util, java/builtins
Ref: Java Docs — Hashtable
Tags: #public #prog #java #stdlib #java_util #tier/legacy


Import

import java.util.*;

Signature & Overview

java.util.Hashtable<K, V>

Java 1.0 globally-synchronized hash table with high lock contention.

Legacy / Avoid: Prefer ConcurrentHashMap in all modern Java.

Notes & Pitfalls

Example

// Prefer HashMap or ConcurrentHashMap over legacy Hashtable:
var map = new java.util.concurrent.ConcurrentHashMap<String, Integer>();
map.put("hits", 1);
assert map.get("hits") == 1;

Linked from

Related notes