Home Tutorial Java Core HashMap Example of keySet method of HashMap.

 
 

Share on Google+Share on Google+
Example of keySet method of HashMap.
Posted on: April 5, 2011 at 12:00 AM
Advertisement
Example of keySet method of HashMap.

Example of keySet method of HashMap.

In this example, we will introduce to you about the keySet method of HashMap. It returns a Set of keys of HashMap.

Code

HashMapKeySet.java

package net.roseindia.java;

import java.util.HashMap;

import java.util.Set;

public class HashMapKeySet {

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 obKeySet = obHashMap.keySet();

System.out.println("Set of Keys : " + obKeySet); } }

Output :
Set of Keys : [1, 2, 3, 4, 5]
Advertisement

Related Tags for Example of keySet method of HashMap.:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 5, 2011

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com