Course contentsShow
← Java
Lesson 1146 of 2,87026. Map ImplementationsFree lesson

What Counts as Access: get and put Operations

Understand which operations trigger reordering in access-order mode: get, put, putIfAbsent, and their effects.

What Counts as Access: get and put Operations

You'll learn which specific operations trigger the reordering behavior in access-order LinkedHashMaps.

When you create a LinkedHashMap with accessOrder set to true, the map tracks when entries are "accessed" and moves them to the end of the iteration order. But what exactly counts as an access?

Operations That Trigger Reordering

In access-order mode, only certain operations count as accesses:

  • get(key) – Reading a value moves that entry to the end
  • put(key, value) – Adding or updating a value moves that entry to the end
  • putIfAbsent(key, value) – Only moves the entry if it actually inserts a new value

Think of it like a "recently used" list on your phone. Opening an app (get) or installing/updating one (put) moves it to the front of your recent apps list. Just checking if an app exists without opening it wouldn't update the order.

What Doesn't Count

Operations like containsKey() or containsValue() don't trigger reordering—they're read-only queries that don't count as "using" the entry. Similarly, if putIfAbsent finds an existing key, it doesn't reorder because it didn't actually modify anything.

Why This Matters

This precise definition lets you implement caching strategies (like LRU caches) where you want entries moved to the end only when they're genuinely used, not just checked for existence.

Key Takeaway: In access-order LinkedHashMap, only get, put (when updating/inserting), and putIfAbsent (when inserting) move entries to the end of iteration order—other query operations don't trigger reordering.