Site icon JavaGoal

entrySet() method

entrySet(): This entrySet Hashmap method employs fetching the Set view of all keys and values in Java. It returns all the key and values in form of Set. This entry Set worked on backed of HashMap, if any change makes in HashMap also reflects in this Set and vice versa. It returns type is Set.

Set<Map.Entry<K,V>> entrySet();

Where, K represents the type Keys in HashMap.
V represents the type Values in HashMap.

import java.util.HashMap;

public class ExampleOfHashMap 
{
	public static void main(String[] args) 
	{
		HashMap<Integer,String> listOfNames = new HashMap<Integer, String>();
		
		listOfNames.put(1, "JAVA");
		listOfNames.put(2, "GOAL");
		listOfNames.put(3, "RAVI");
		
		System.out.println("Keys and values set of Map = "+listOfNames.entrySet());
		
	}
}

Output: Keys and values set of Map = [1=JAVA, 2=GOAL, 3=RAVI]

Exit mobile version