 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to retrieve the set of all keys in HashMap
First, create a HashMap and add elements
HashMap hm = new HashMap(); hm.put("Wallet", new Integer(700)); hm.put("Belt", new Integer(600)); hm.put("Backpack", new Integer(1200)); Now, retrieve all the keys
Set keys = hm.keySet(); System.out.println("\nKeys..."); Iterator i = keys.iterator(); while (i.hasNext()) {    System.out.println(i.next()); } The following is an example to get the set of all key in HashMap
Example
import java.util.*; public class Demo { public static void main(String args[]) { // Create hash map HashMap hm = new HashMap(); hm.put("Wallet", new Integer(700)); hm.put("Belt", new Integer(600)); hm.put("Backpack", new Integer(1200)); System.out.println("Map = "+hm); Set keys = hm.keySet(); System.out.println("\nKeys..."); Iterator i = keys.iterator(); while (i.hasNext()) { System.out.println(i.next()); } } } The following is the output
Map = {Backpack=1200, Belt=600, Wallet=700} Keys... Backpack Belt WalletAdvertisements
 