I met Map.Entry for many times when I was fighting with Leetcode. However, I did not understand it and it always confused me. I studied it today and write down to record it for myself.

(:Click here for java documention:)

Map.Entry is a internal interface of Map. It provides more convenient method for outputing key-value pair.

How do we output key-value pair of a Map generally?

  • First, get all keys as a set
  • Second, iterate to get every value according to keyset.

If we have Map.Entry, we will get key and value at meantime.

Some important methods:

Return TypeMethodDescription
KgetKey()Returns the key corresponding to this entry.
VgetValue()Returns the value corresponding to this entry.