Map.Entry interface enables you to work with a map entry.
The entrySet() method declared by the Map interface returns a Set containing the map entries.
Each of these set elements is a Map.Entry object.
Map.Entry is generic and is declared like this:
interface Map.Entry<K, V>
Here, K specifies the type of keys, and V specifies the type of values.
The following table summarizes the non-static methods declared by Map.Entry.
| Method |    Description | 
|---|---|
| boolean |    equals(Object obj)                                                   Returns true if obj is a *Map. Entry* whose key and value are equal to that of the invoking object.  | 
| K |    getKey()                            Returns the key for this map entry.  | 
| V |    getValue()                            Returns the value for this map entry.  | 
| int |    hashCode()                                Returns the hash code for this map entry.  | 
| V |    setValue(V v)                                                              Sets the value for this map entry to v. A ClassCastException is thrown if v is not the correct type for the map. An IllegalArgumentException is thrown if there is a problem with v.  | 
JDK 8 adds two static methods.
The first is comparingByKey(), which returns a Comparator that compares entries by key.
The second is comparingByValue(), which returns a Comparator that compares entries by value.
A NullPointerException is thrown if v is null and the map does not permit null keys.
An UnsupportedOperationException is thrown if the map cannot be changed.
PreviousNext