In Java, the Stream class was introduced as a part of the Java 8 Streams API that provides a functional way of processing collections of objects, i.e. a sequence of elements that can be processed in a functional manner.
With the help of the Stream class, you can perform various operations on collections like filtering, mapping, sorting, reducing, and more, without modifying the original collection.
Convert Map<K,V> as List<E>
To convert a Map to a List in Java 8 using Stream,
Step 1: We can use the entrySet() method of the Map interface to get a set of the map's key-value pairs.
Step 2: We can then use the stream() method to convert the set to a stream,
Step 3: We use the map() method to transform each entry into an object of your desired type
Step 4: Lastly, we can make use of the collect() method to collect the stream into a List.
Example:package org.example;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
*
* Code Example in Java 8 to convert
* Map to List using Stream API
*
*
*/
public class MapToList {
public static void main(String[] args) {
Map<String,String> cityTempMap = new HashMap<>();
cityTempMap.put("NYC","34");
cityTempMap.put("Chicago","32");
cityTempMap.put("Austin","42");
cityTempMap.put("Huston","31");
cityTempMap.put("Ohio","30");
//Map to List
List<String> cities = cityTempMap
.entrySet() //Step 1:entrySet() to get K-V Pair
.stream() //Step 2: Convert Set to Steam
.map(entry -> entry.getKey()) // Step 3: Use map() to transform
.collect(Collectors.toList()); // Step 4: Collect Steam as List
System.out.println(cities);
}
}
Output:
[Chicago, NYC, Ohio, Austin, Huston]

Have Questions? Post them here!
- How to Get List of All Country Codes in Java Using Locale Class
- Unsupported major.minor version 52.0 in java
- Java - How to set custom thread name?
- Get the current timestamp in Java
- Java Spring Boot 3 Web Hello World with Gradle in IntelliJ
- [fix] NullPointerException Cannot Invoke findById because Repository is null - Java Spring
- java: unclosed string literal [Error]
- Convert Java Byte Array to String with code examples
- Error: Can not find the tag library descriptor for
- Java 8 - Convert List to Map Examples
- Java - Calculate time taken for the code to execute in milliseconds or nanoseconds
- Fix java.net.ProtocolException: Invalid HTTP method
- Java: Convert Stream to List
- Java equals method - Tutorial
- List of Java JDBC Database Driver Jars, Classes and URLs Details
- Read YAML file Java Jackson Library
- How to display Java Date Time timezone GMT/UTC offset using SimpleDateFormat
- List of Java Keywords
- Enable JSON Pretty Print in Java Jackson
- How to Word-Warp Console logs in IntelliJ
- Convert Map to List in Java 8 using Stream API
- Create a Directory using Java Code
- Ways to Convert Integer or int to Long in Java
- [Program] How to read three different values using Scanner in Java
- Java JDBC Example with Oracle Database Driver Connection
- How to know the Serial Number of MacBook on macOS Ventura 13.0 - MacOS
- How to install Java on macOS [Big Sur] - MacOS
- Vertical align two div's in Bootstrap [HTML CSS] - Bootstrap
- How to extract Java Jar/War/Ear files in Linux - Java
- Remove mailto link from Microsoft 365 Word Document Email Text - Microsoft
- HTML5 HELLO WORLD Example - Html
- How to Copy files from Docker Container to Host System - Docker
- Android-Failed to install apk on device EOF Timeout Error - Android