Press "Enter" to skip to content

HashMap entrySet() Method in Java

The entrySet() method of HashMap returns the set view of the entries in this map.


Set<Entry<K, V>> entrySet()


It does not take any parameters.

Return Value

It returns the set of entries


import java.util.HashMap;
import java.util.Map;

public class HashMapEntrySetExample {

	public static void main(String[] args) {

		Map<Integer, String> map = new HashMap<>();
		map.put(101, "John");
		map.put(102, "Adam");
		map.put(103, "Ricky");
		map.put(104, "Chris");

		System.out.println("Key-Value entries in map: " + map.entrySet());


Key-Value entries in map: [101=John, 102=Adam, 103=Ricky, 104=Chris]

Be First to Comment

Leave a Reply

Your email address will not be published.