Example
Retrieve all the mappings contained within a map.
import java.util.HashMap;
public class Main {
public static void main(String[] args) {
HashMap<String, String> capitalCities = new HashMap<String, String>();
capitalCities.put("England", "London");
capitalCities.put("Germany", "Berlin");
capitalCities.put("Norway", "Oslo");
capitalCities.put("USA", "Washington DC");
System.out.println(capitalCities.entrySet());
}
}
|
Definition and Usage
The entrySet() method returns a set containing all of the entries in the map.
Note: The returned set is a view of the map, which means that changing the set also changes the map.
Syntax
public Set< Map.Entry<K,V> > entrySet()
|
K and V denote the data types of the keys and values within the map.
Technical Details
|
Returns:
|
A set comprising all entries present in the map.
|