What is the AbstractMap entrySet() method in Java?
Overview
We use the entrySet() method of the AbstractMap class to get the view of the key-value pairs (mappings) contained in the abstract map.
Method
public abstract Set<Entry<K,V>> entrySet();
Parameters
The method has no parameters.
Return value
The method returns a set view of the mappings in the map.
Example
import java.util.*;public class Main{public static void main(String[] args) {AbstractMap<String, String> abstractMap = new HashMap<>();abstractMap.put("hello-1", "Educative");abstractMap.put("hello-2", "edpresso");abstractMap.put("hello-3", "answers");System.out.println(abstractMap.entrySet());}}
Explanation
- Line 5: An abstract map is defined. The abstract map has the implementation of the hash map.
- Lines 6–8: Add entries to the map using the
put()method. - Line 9: Obtain the map’s entries by invoking the
entrySet()method and print the result.
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved