Example of entrySet method of HashMap.


 

Example of entrySet method of HashMap.

In this tutorial you will learn about the entrySet method of HashMap class.

In this tutorial you will learn about the entrySet method of HashMap class.

Example of entrySet method of HashMap.

In this example, we will introduce to you about the entySet method of HashMap. It returns a Set of all entries of HashMap.

Code

HashMapKeySet.java

package net.roseindia.java;

import java.util.HashMap;

import java.util.Set;

public class HashMapEntrySet {

public static void main(String[] arr) {

/* Create object of HashMap */

HashMap<Integer, String> obHashMap = new HashMap<Integer, String>();

/* Strore value in HashMap */

obHashMap.put(new Integer(1), "AAA");

obHashMap.put(new Integer(2), "BBB");

obHashMap.put(new Integer(3), "CCC");

obHashMap.put(new Integer(4), "DDD");

obHashMap.put(new Integer(5), "EEE");

/* Create a set of keys of hashmap */

Set obEntrySet = obHashMap.entrySet();

System.out.println("Set of entries : " + obEntrySet); } }

Output :
Set of entries : [1=AAA, 2=BBB, 3=CCC, 4=DDD, 5=EEE]

Ads