Back to blogNo duplicate keys Each key maps to one value Fast lookups by key No guaranteed order Very fast access Use case: account balance lookup Preserves insertion order Use case: ordered configuration rules Keys stored in sorted order Use case: tiered pricing or limits HashMap → fastest key-based access, no ordering guarantees LinkedHashMap → predictable iteration order with slight overhead TreeMap → sorted keys using natural order or Comparator
January 10, 2026•6 min read•Marina
Java Collections in Real Systems | Part 3: Map
JavaCollectionsMap
Java Collections in Real Systems | Part 3: Map
If List is about order and Set about uniqueness, Map is about relationships.
Everything revolves around key → value.
Map
HashMap
Map<String, BigDecimal> balances = new HashMap<>();
balances.put("ACC1", new BigDecimal("1000"));
balances.put("ACC2", new BigDecimal("2500"));
balances.put("ACC3", new BigDecimal("500"));
balances.put("ACC2", new BigDecimal("3000")); // value overwrittenLinkedHashMap
Map<String, String> rules = new LinkedHashMap<>();
rules.put("RULE1", "VALIDATE");
rules.put("RULE2", "AUTHORIZE");
rules.put("RULE3", "SETTLE");
rules.put("RULE2", "REAUTHORIZE"); // overwrites value, keeps orderTreeMap
Map<Integer, String> riskLevels = new TreeMap<>();
riskLevels.put(3, "HIGH");
riskLevels.put(1, "LOW");
riskLevels.put(2, "MEDIUM");
riskLevels.put(2, "MEDIUM_PLUS"); // overwrites valueThink
If you want the big-picture comparison between List, Set, and Map, read the intro:
List, Set, and Map: Key Differences in Java Collections.
Previous in the series:
Java Collections in Real Systems | Part 2: List.
Next: Ready to test your understanding?