I am reading Javadoc for LinkedHashMap, where it is mentioned:
The putAll method generates one entry access for each mapping in the
specified map, in the order that key-value mappings are provided by
the specified map’s entry set iterator.
My question is, what does it mean “one entry access for each mapping”. It would be appreciated if anyone could help to provide an example to clarify this.
This paragraph applies to maps created with the special constructor that makes the iteration order based on last access order (vs. insertion order for a standard LinkedHashMap.
It simply says that if a key
Kis in the map and you callputAll(someOtherMap)wheresomeOtherMapcontainsKtoo, this will be considered as an access toKand it will be moved to the end of the map (from an iteration order’s perspective).In other words, from an access perspective,
putAllis equivalent tofor (Entry e : entries) map.put(e);(in pseudo code).Contrived example: