Well, you want to collect Pair elements into a List. That means that you need to map your Stream<Map.Entry<String, Double>> into a Stream<Pair<String, Double>>.

This is done with the map operation:

Returns a stream consisting of the results of applying the given function to the elements of this stream.

In this case, the function will be a function converting a Map.Entry<String, Double> into a Pair<String, Double>.

Finally, you want to collect that into a List, so we can use the built-in toList() collector.

List<Pair<String, Double>> mostRelevantTitles = 
    implicitDataSum.entrySet()
                   .stream()
                   .sorted(Comparator.comparing(e -> -e.getValue()))
                   .map(e -> new Pair<>(e.getKey(), e.getValue()))
                   .collect(Collectors.toList());

Note that you could replace the comparator Comparator.comparing(e -> -e.getValue()) by Map.Entry.comparingByValue(Comparator.reverseOrder()).

Answer from Tunaki on Stack Overflow
๐ŸŒ
Mkyong
mkyong.com โ€บ home โ€บ java8 โ€บ java 8 โ€“ convert map to list
Java 8 โ€“ Convert Map to List | mkyong.com
May 24, 2017 - Map<String, String> map = new HashMap<>(); // Convert all Map keys to a List List<String> result = new ArrayList(map.keySet()); // Convert all Map values to a List List<String> result2 = new ArrayList(map.values()); // Java 8, Convert all Map ...
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ java-convert-map-to-list
Java 8: How to Convert a Map to List
October 10, 2023 - In this tutorial, we'll take a look at how to convert a Java Map to a Java List: ... Java 8 introduced us to the Stream API - which were meant as a step towards integrating Functional Programming into Java to make laborious, bulky tasks more readable and simple.
๐ŸŒ
Mkyong
mkyong.com โ€บ home โ€บ java8 โ€บ java 8 โ€“ convert list to map
Java 8 โ€“ Convert List to Map | mkyong.com
May 26, 2017 - Map<String, Long> result1 = list.stream().collect( Collectors.toMap(Hosting::getName, Hosting::getWebsites, (oldValue, newValue) -> newvalue ) ); ... package com.mkyong.java8; import java.util.*; import java.util.stream.Collectors; public class TestSortCollect { public static void main(String[] args) { List<Hosting> list = new ArrayList<>(); list.add(new Hosting(1, "liquidweb.com", 80000)); list.add(new Hosting(2, "linode.com", 90000)); list.add(new Hosting(3, "digitalocean.com", 120000)); list.add(new Hosting(4, "aws.amazon.com", 200000)); list.add(new Hosting(5, "mkyong.com", 1)); list.add(n
๐ŸŒ
Java67
java67.com โ€บ 2019 โ€บ 12 โ€บ how-to-convert-map-to-list-in-java-8.html
3 Examples to convert a Map to List in Java 8 - Example Tutorial | Java67
Since Set cannot have duplicates and Map also cannot have duplicate keys, the Set data structure seems to be perfect for returning keys and entries. But, values can be duplicated in Map; hence API provides values() method which returns Collection. Before Java 8, the problem of converting a Map to List is actually a problem of converting Map to Set and then to List, which is also not different in Java 8.
Top answer
1 of 4
29

Well, you want to collect Pair elements into a List. That means that you need to map your Stream<Map.Entry<String, Double>> into a Stream<Pair<String, Double>>.

This is done with the map operation:

Returns a stream consisting of the results of applying the given function to the elements of this stream.

In this case, the function will be a function converting a Map.Entry<String, Double> into a Pair<String, Double>.

Finally, you want to collect that into a List, so we can use the built-in toList() collector.

List<Pair<String, Double>> mostRelevantTitles = 
    implicitDataSum.entrySet()
                   .stream()
                   .sorted(Comparator.comparing(e -> -e.getValue()))
                   .map(e -> new Pair<>(e.getKey(), e.getValue()))
                   .collect(Collectors.toList());

Note that you could replace the comparator Comparator.comparing(e -> -e.getValue()) by Map.Entry.comparingByValue(Comparator.reverseOrder()).

2 of 4
9

Note that if you want efficient implementation, you should consider this:

List<Pair<String, Double>> mostRelevantTitles = 
    implicitDataSum.entrySet()
                   .stream()
                   .map(e -> new Pair<>(e.getKey(), e.getValue()))
                   .collect(Collectors.toList());
mostRelevantTitles.sort(Comparators.comparing(Pair::getSecond, Comparator.reverseOrder()));

I assume that your Pair class have getSecond getter.

Using the sorted() stream pipeline step you create intermediate buffer, store everything to that buffer, convert it into array, sort that array, then store the result into the ArrayList. My approach, though less functional, stores data directly into the target ArrayList, then sorts it in-place without any additional copying. So my solution would take less time and intermediate memory.

๐ŸŒ
ConcretePage
concretepage.com โ€บ java โ€บ jdk-8 โ€บ java-8-convert-map-to-list-using-collectors-tolist-example
Java 8 Convert Map to List using Collectors.toList()
--Convert Map Values to List-- Mahesh Suresh Dinesh Kamlesh --Convert Map Values to List using sort-- Dinesh Kamlesh Mahesh Suresh --Convert Map keys to List-- 23 10 26 11 --Convert Map keys to List using sort-- 10 11 23 26 ... package com.concretepage; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; public class MapToListOfUserObject { public static void main(String[] args) { Map&ltInteger, String&gt map = new HashMap&lt&gt(); map.put(23, "Mahesh"); map.put(10, "Suresh"); map.put(26, "Dinesh"); map.put(11, "Kamlesh"); List&ltPerson&gt list = map.entrySet().stream().sorted(Comparator.comparing(e -&gt e.getKey())) .map(e -&gt new Person(e.getKey(), e.getValue())).collect(Collectors.toList()); list.forEach(l -&gt System.out.println("Id: "+ l.getId()+", Name: "+ l.getName())); } } Person.java
๐ŸŒ
Javaprogramto
javaprogramto.com โ€บ 2020 โ€บ 08 โ€บ java-8-convert-map-to-list-hashmap-to-arraylist.html
Java 8 โ€“ Convert Map to List (HashMap to ArrayList)
August 16, 2020 - Instead of using the ArrayList constructor, we are using stream() method to convert HashMap to ArrayList. package com.javaprogramto.java8.maptolist; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.str...
๐ŸŒ
Techie Delight
techiedelight.com โ€บ home โ€บ java โ€บ convert map to a list in java 8 and above
Convert Map to a List in Java 8 and above | Techie Delight
July 7, 2026 - This post will discuss how to convert map to a list in Java. We know that Map.entrySet() returns a set view of the mappings contained in this map. In Java 8, we can easily get a list of key-value pairs by converting it to stream, as shown below:
Find elsewhere
๐ŸŒ
Medium
medium.com โ€บ @vino7tech โ€บ java-8-stream-convert-map-to-list-and-list-to-map-using-employee-example-514c27b23c13
Java 8 Stream : Convert Map to List and List to Map Using Employee Object Example | by Vinotech | Medium
November 25, 2025 - Learn how to convert Map to List and List to Map in Java 8 using Stream API. This guide uses a real Employee object with sample input and output, covering collectors, key mapping, value mapping, and handling duplicates.
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 680277 โ€บ java โ€บ Creating-map-maps-list-Java
Creating a map of maps from a list using Java 8 streams [Solved] (Java in General forum at Coderanch)
The key of the first map is MonitoredData::getDayOfYear and the key to the second map is MonitoredData::getActivityLabel. The value of the second data should be the number of times the certain activity has been found in that specific day. Thanks in advance, tell me if there's something else ...
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java collections โ€บ java map โ€บ how to convert list to map in java
How to Convert List to Map in Java | Baeldung
April 4, 2025 - A solid grasp of the fundamentals will go a long way to help minimize these issues. Get started with understanding multi-threaded applications with our Java Concurrency guide: ... Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ conversion-of-java-maps-to-list
Conversion of Java Map to List - GeeksforGeeks
July 11, 2025 - In Java, a Map is a collection that maps keys to values and a list is an ordered collection of objects and the List can contain duplicate values. There are some scenarios where we need to convert a Map into a List.
๐ŸŒ
Spring Framework Guru
springframework.guru โ€บ home โ€บ converting java map to list
Converting Java Map to List - Spring Framework Guru
June 25, 2019 - If you are into functional programming style, you can use streams introduced in Java 8, along with some utility classes like Collectors, which provides several useful methods to convert stream of Map entries to List.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java collections โ€บ java map โ€บ convert a map to an array, list or set in java
Convert a Map to an Array, List or Set in Java | Baeldung
June 9, 2025 - This short article will show how to convert the values of a Map to an Array, a List or a Set using plain Java as well as a quick Guava based example.
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 698071 โ€บ java โ€บ Converting-List-Map
Converting from List To Map? (Features new in Java 8 forum at Coderanch)
August 21, 2018 - With the toMap, it means that when we have two equal Strings, we need to put the two associated Words into a List. Now, that is not so easy to accomplish with the toMap method, but the alternative mappng method is in this case very much easier. I'm talking about the Collectors.groupingBy method.
๐ŸŒ
Blogger
javarevisited.blogspot.com โ€บ 2016 โ€บ 04 โ€บ 10-examples-of-converting-list-to-map.html
10 Examples of Converting a List to Map in Java 8
In the past, we have seen how to use the Collectors.groupingBy() method to group elements in Set and In this article, we will use Collectors.toMap() method to convert a List of an object into a Map in Java.
๐ŸŒ
Blogger
javarevisited.blogspot.com โ€บ 2011 โ€บ 12 โ€บ how-to-convert-map-to-list-in-java.html
How to Convert a Map to a List in Java - Example Tutorial
August 25, 2022 - That's all on Map to List Conversion in Java, as you have seen in the above example you can create a separate list for both keySet and values of HashMap as Map API return Set of keys and values of Collection in Java. As I said, from Java 8 onwards you can also use Stream API to do this conversion, you can see this example of converting Map to List using Stream in Java as well.
๐ŸŒ
LinkedIn
linkedin.com โ€บ pulse โ€บ converting-map-list-java-8-collectors-saral-saxena
Converting map to list --Java 8 collectors
Login to LinkedIn to keep in touch with people you know, share ideas, and build your career.