You need to stream the entries and collect them in a new map:

Map<String, String> result = map.entrySet()
    .stream()
    .collect(Collectors.toMap(Entry::getKey, e -> String.valueOf(e.getValue()));
Answer from assylias on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › map-values-method-in-java-with-examples
Map Values() Method in Java With Examples - GeeksforGeeks
December 19, 2025 - The values() method of the Map interface returns a Collection view of all values stored in the map. The returned collection is backed by the map, meaning any modification to the map is immediately reflected in the collection and vice versa.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › Map.html
Map (Java Platform SE 8 )
July 21, 2026 - The Map interface provides three collection views, which allow a map's contents to be viewed as a set of keys, collection of values, or set of key-value mappings. The order of a map is defined as the order in which the iterators on the map's collection views return their elements.
🌐
GeeksforGeeks
geeksforgeeks.org › java › hashmap-values-method-in-java
HashMap values() Method in Java - GeeksforGeeks
January 9, 2026 - values() method retrieves a collection containing all values present in the map.
🌐
W3Schools
w3schools.com › java › ref_hashmap_values.asp
Java HashMap values() Method
import java.util.HashMap; public ... System.out.println(capitalCities.values()); } } ... The values() method returns a collection containing all of the values in the map....
🌐
Programiz
programiz.com › java-programming › library › hashmap › values
Java HashMap values()
The values() method can also be used with the for-each loop to iterate through each value of the hashmap. import java.util.HashMap; class Main { public static void main(String[] args) { // Creating a HashMap HashMap<String, Integer> numbers = new HashMap<>(); numbers.put("One", 1); ...
🌐
Vultr
docs.vultr.com › java › standard library › java › util › hashmap › values()
Java HashMap values() - Retrieve All Values
September 27, 2024 - Use the values() method to fetch the values. ... import java.util.HashMap; import java.util.Collection; public class Main { public static void main(String[] args) { HashMap<Integer, String> map = new HashMap<>(); map.put(1, "Java"); map.put(2, "Python"); map.put(3, "C++"); Collection<String> ...
🌐
DEV Community
dev.to › harini_magesh_fa40041cf8d › map-in-java-5df6
Map in Java - DEV Community
June 16, 2026 - A key uniquely identifies a value. ... import java.util.*; public class Main { public static void main(String[] args) { Map<Integer, String> map = new HashMap<>(); map.put(101, "Harini"); map.put(102, "Rahul"); map.put(103, "Kaviya"); System.out.println(map); } }
Find elsewhere
🌐
Stackify
stackify.com › an-introduction-to-java-map-what-it-is-and-how-it-works
An Introduction to Java Map: What It Is and How It Works - Stackify
November 26, 2024 - The Java Map interface stores data in key-value pairs, which makes it different from other collections such as List and Set. Each key in a map is unique, meaning no duplicate keys are allowed. However, values can be duplicated.
Top answer
1 of 11
132

To get all the values from a map:

for (Tab tab : hash.values()) {
    // do something with tab
}

To get all the entries from a map:

for ( Map.Entry<String, Tab> entry : hash.entrySet()) {
    String key = entry.getKey();
    Tab tab = entry.getValue();
    // do something with key and/or tab
}

Java 8 update:

To process all values:

hash.values().forEach(tab -> /* do something with tab */);

To process all entries:

hash.forEach((key, tab) -> /* do something with key and tab */);
2 of 11
42

Map is internally made up of Map.Entry objects. Each Entry contains key and value. To get key and value from the entry you use accessor and modifier methods.

If you want to get values with given key, use get() method and to insert value, use put() method.

#Define and initialize map;
Map map = new HashMap();
map.put("USA",1)
map.put("Japan",3)
map.put("China",2)
map.put("India",5)
map.put("Germany",4)

map.get("Germany") // returns 4

If you want to get the set of keys from map, you can use keySet() method

Set keys = map.keySet();
System.out.println("All keys are: " + keys);
// To get all key: value
for(String key: keys){
    System.out.println(key + ": " + map.get(key));
}

Generally, To get all keys and values from the map, you have to follow the sequence in the following order:

  • Convert Hashmap to MapSet to get set of entries in Map with entryset() method.:
    Set st = map.entrySet();
  • Get the iterator of this set:
    Iterator it = st.iterator();
  • Get Map.Entry from the iterator:
    Map.Entry entry = it.next();
  • use getKey() and getValue() methods of the Map.Entry to get keys and values.
// Now access it
Set st = (Set) map.entrySet();
Iterator it = st.iterator();
while(it.hasNext()){
    Map.Entry entry = mapIterator.next();
    System.out.print(entry.getKey() + " : " + entry.getValue());
}

In short, use iterator directly in for

for(Map.Entry entry:map.entrySet()){
    System.out.print(entry.getKey() + " : " + entry.getValue());
}
🌐
Mkyong
mkyong.com › home › java › java – how to get keys and values from map
Java – How to get keys and values from Map | mkyong.com
August 10, 2019 - package com.mkyong; import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.Set; public class JavaMapExample { public static void main(String[] args) { Map<String, String> map = new HashMap<>(); map.put("db", "oracle"); map.put("username", "user1"); map.put("password", "pass1"); // Get keys and values for (Map.Entry<String, String> entry : map.entrySet()) { String k = entry.getKey(); String v = entry.getValue(); System.out.println("Key: " + k + ", Value: " + v); } // Get all keys Set<String> keys = map.keySet(); for (String k : keys) { System.out.println("Key: " + k); } // Get all values Collection<String> values = map.values(); for (String v : values) { System.out.println("Value: " + v); } // Java 8 map.forEach((k, v) -> { System.out.println("Key: " + k + ", Value: " + v); }); } }
🌐
Baeldung
baeldung.com › home › java › java collections › java map › java map – keyset() vs. entryset() vs. values() methods
Java Map – keySet() vs. entrySet() vs. values() Methods | Baeldung
January 8, 2024 - Here, we’ve chosen the AbstractMap.SimpleEntry implementation of the interface Map.Entry for our test. The values() method returns the Collection of values contained in the Map.
🌐
Baeldung
baeldung.com › home › java › java collections › java map › get values and keys as arraylist from a hashmap
Get Values and Keys as ArrayList From a HashMap | Baeldung
March 7, 2025 - When we manipulate data structures in Java, one common scenario involves extracting values and keys from a HashMap and organizing them into an ArrayList. In this quick tutorial, we’ll explore various practical approaches to achieving this goal. First, let’s create a HashMap object as the input example: static final HashMap<String, String> DEV_MAP; static { DEV_MAP = new HashMap<>(); DEV_MAP.put("Kent", "Linux"); DEV_MAP.put("Eric", "MacOS"); DEV_MAP.put("Kevin", "Windows"); DEV_MAP.put("Michal", "MacOS"); DEV_MAP.put("Saajan", "Linux"); }
🌐
Jenkov
jenkov.com › tutorials › java-collections › map.html
Java Map
Only Java objects can be used as keys and values in a Java Map. In case you pass primitive values (e.g. int, double etc.) to a Map as key or value, the primitive values will be auto-boxed before being passed as parameters.
🌐
CodeSignal
codesignal.com › learn › courses › mastering-complex-data-structures-in-java › lessons › exploring-maps-and-hashmap-in-java
Exploring Maps and HashMap in Java
Today, we will delve deeply into Java Maps. Much like a bookshelf, Maps allow you to quickly select the book (value) you desire by reading its label (key). They are vital in Java for quickly accessing values using keys and for efficiently inserting and deleting keys.
🌐
Medium
medium.com › javarevisited › maps-are-an-important-data-structure-in-java-that-store-key-value-pairs-8fba84fe8a1f
Maps are an important data structure in Java that store key-value pairs.
October 31, 2023 - HashMap Implementation HashMap is a hash table implementation of the Map interface. It uses a hash function to compute the hash code of each key, which is used to index into an array of buckets that store the key-value pairs. In case of a collision, the key-value pairs are stored in a linked list. HashMap provides constant-time performance for the basic operations (put(), get(), and remove()) on average, as long as the hash function distributes the keys evenly across the buckets ... A humble place to learn Java and Programming better.
🌐
Oracle
docs.oracle.com › javase › 6 › docs › api › java › util › Map.html
Map (Java Platform SE 6)
The Map interface provides three collection views, which allow a map's contents to be viewed as a set of keys, collection of values, or set of key-value mappings. The order of a map is defined as the order in which the iterators on the map's collection views return their elements.
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.base › java › util › Map.html
Map (Java SE 11 & JDK 11 )
January 20, 2026 - The Map interface provides three collection views, which allow a map's contents to be viewed as a set of keys, collection of values, or set of key-value mappings. The order of a map is defined as the order in which the iterators on the map's collection views return their elements.
🌐
W3Schools
w3schools.com › java › java_hashmap.asp
Java HashMap
It is part of the java.util package and implements the Map interface. Instead of accessing elements by an index (like with ArrayList), you use a key to retrieve its associated value.
🌐
Stack Abuse
stackabuse.com › java-how-to-get-keys-and-values-from-a-map
Java: How to Get Keys and Values from a Map
November 24, 2020 - Key-value stores are essential ... the value. This way, the values can easily be retrieved, by looking up the key. In Java, the most popular Map implementation is the HashMap class....