Get LinkedList of entries from LinkedHashMap with values() method
As of Java 8, let's take a look at the source of LinkedHashMap
. We can deduct the internal behavior from the entrySet()
and values()
method definitions:
- The method
entrySet()
returnsnew LinkedEntrySet()
on the line 627 which usesnew LinkedEntryIterator()
as the iterator as of line 634. - The method
values()
returnsnew LinkedValues()
on the line 581 which usesnew LinkedValueIterator()
as the iterator as of line 588.
Now, let's look at the sources of those inner classes defined in the very same file beginning from line 737:
final class LinkedValueIterator extends LinkedHashIterator
implements Iterator<V> {
public final V next() { return nextNode().value; }
}
final class LinkedEntryIterator extends LinkedHashIterator
implements Iterator<Map.Entry<K,V>> {
public final Map.Entry<K,V> next() { return nextNode(); }
}
They both extend LinkedHashIterator
which implies the accessing of values of the map would be treated the same way using both entrySet()
and values()
.