Java HashMapentrySet() Method
Example
Return all the entries in 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
TheentrySet() method returns a set containing all of the entries in the map.
To learn about sets, see ourJava HashSet tutorial.
Note: The returned set is aview of the map, which means that changing the set also changes the map.
Syntax
public Set< Map.Entry<K,V> > entrySet()K andV refer to the data types of the keys and values of the map.
Technical Details
| Returns: | A set containing all of the entries in the map. |
|---|
Related Pages
❮ HashMap Methods

