Monday, April 29, 2019

Map.Entry Interface in Java

Map store data in form of key-value pair, these pair called entry. These entries are instance of Map.Entry.

Map.Entry is nested interface.

Within Map interface, Entry interface defined as below

interface Entry<K,V>{
getKey();
getValue();
..
.
}

Method in Map.Entry interface 

getKey() - Returns the key corresponding to this entry.
getValue()- Returns the value corresponding to this entry.
setValue(V value)- Replaces the value corresponding to this entry with the specified value (optional operation).
entrySet() - Return Set<Entry<K,V>>  Collection View of map , whose element of type Map.Entry

Java 8 Comparison Method

comparingByKey()- Returns a comparator that compares Map.Entry in natural order on key.
comparingByKey(Comparator<? super K> cmp)- Returns a comparator that compares Map.Entry by key using the given Comparator.
comparingByValue()- Returns a comparator that compares Map.Entry in natural order on value.
comparingByValue(Comparator<? super V> cmp)- Returns a comparator that compares Map.Entry by value using the given Comparator.


No comments:

Post a Comment