HashMap entrySet() Method in Java

Published by user on

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

Syntax

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

Parameters

It does not take any parameters.

Return Value

It returns the set of entries

Program

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());
	}
}

Output

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

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *