- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Extract values from HashMap in Java
To extract values from HashMap, let us first create a HashMap with keys and values −
HashMap<Integer, Integer>m = new HashMap<Integer, Integer>();
Now, add some elements to the HashMap −
m.put(10, 20); m.put(30, 40); m.put(50, 60); m.put(70, 80); m.put(90, 100); m.put(110, 120); m.put(130, 140); m.put(150, 160);
Now, extract the values from the HashMap −
for (Integer i: m.keySet()) { System.out.println(m.get(i)); }
Example
import java.util.HashMap; public class Demo { public static void main(String args[]) { HashMap<Integer, Integer>m = new HashMap<Integer, Integer>(); m.put(10, 20); m.put(30, 40); m.put(50, 60); m.put(70, 80); m.put(90, 100); m.put(110, 120); m.put(130, 140); m.put(150, 160); System.out.println("Displaying values from HashMap..."); for (Integer i: m.keySet()) { System.out.println(m.get(i)); } } }
Output
Displaying values from HashMap... 60 140 80 160 20 100 40 120
- Related Articles
- Remove all values from HashMap in Java
- Iterate through the values of HashMap in Java
- Sorting a HashMap according to values in Java
- Remove value from HashMap in Java
- Retrieve all the keys from HashMap in Java
- Extract unique values from an array - JavaScript
- Java Program to retrieve the set of all values in HashMap
- HashMap in Java
- Initialize HashMap in Java
- Clone HashMap in Java
- Java Program to retrieve the set of all keys and values in HashMap
- Java Program to remove key value pair from HashMap?
- Java Program to remove a key from a HashMap
- Retrieve a set of Map.Entry elements from a HashMap in Java
- Create a HashMap in Java

Advertisements