You say you want to sort by value, but you don't have that in your code. Pass a lambda (or method reference) to sorted to tell it how you want to sort.

And you want to get the keys; use map to transform entries to keys.

List<Type> types = countByType.entrySet().stream()
        .sorted(Comparator.comparing(Map.Entry::getValue))
        .map(Map.Entry::getKey)
        .collect(Collectors.toList());
Answer from Jesper on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ stream-map-java-examples
Stream map() in Java with examples - GeeksforGeeks
January 4, 2025 - // Java code for Stream map(Function mapper) // to get a stream by applying the // given function to this stream. import java.util.*; import java.util.stream.Collectors; class GFG { // Driver code public static void main(String[] args) { System.out.println("The stream after applying " + "the function is : "); // Creating a list of Integers List<String> list = Arrays.asList("geeks", "gfg", "g", "e", "e", "k", "s"); // Using Stream map(Function mapper) to // convert the Strings in stream to // UpperCase form List<String> answer = list.stream().map(String::toUpperCase).
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java streams โ€บ collecting stream elements into a list in java
Collecting Stream Elements into a List in Java | Baeldung
December 3, 2025 - We also know that the Stream API provides the implementation only for the toList() method. It doesnโ€™t contain similar methods for getting a map or a set. So if we want a uniform approach to get any converters, like list, map, or set, weโ€™ll ...
๐ŸŒ
Medium
medium.com โ€บ @AlexanderObregon โ€บ javas-stream-map-method-explained-df0d0d461d39
Javaโ€™s Stream.map() Method Explained | Medium
August 27, 2024 - While working with streams, especially in data processing, you might encounter situations where some elements are null. The map() method can handle such cases gracefully, particularly when combined with the Optional class. For example, letโ€™s say youโ€™re processing a list of strings, some of which might be null. You can use map() to transform the data while safely handling null values: import java.util.Arrays; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; public class MapExample { public static void main(String[] args) { List<String> words = Arrays.asL
๐ŸŒ
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 ...
๐ŸŒ
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 ...
Find elsewhere
๐ŸŒ
Oracle
docs.oracle.com โ€บ javase โ€บ 8 โ€บ docs โ€บ api โ€บ java โ€บ util โ€บ stream โ€บ Stream.html
Stream (Java Platform SE 8 )
July 21, 2026 - When executed in parallel, multiple intermediate results may be instantiated, populated, and merged so as to maintain isolation of mutable data structures. Therefore, even when executed in parallel with non-thread-safe data structures (such as ArrayList), no additional synchronization is needed for a parallel reduction. ... Map<String, List<Person>> peopleByCity = personStream.collect(Collectors.groupingBy(Person::getCity));
๐ŸŒ
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
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ conversion-of-java-maps-to-list
Conversion of Java Map to List - GeeksforGeeks
July 11, 2025 - We can stream the map key or values and collect them into a list. Example: This example demonstrates how to convert the keys and values of a Map into separate List object using Java Streams.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java list โ€บ create list of object from another type using java
Create List of Object From Another Type Using Java | Baeldung
March 7, 2025 - As the code above shows, preparing an empty list for TennisPlayerCandidate objects is unnecessary. The filter().map() pipeline delivers a Stream of TennisPlayerCandidate instances. What we need to do is just collect the objects into a list.
๐ŸŒ
How to do in Java
howtodoinjava.com โ€บ home โ€บ collections framework โ€บ convert list to map in java
Convert List to Map in Java
September 23, 2022 - To resolve this, we have to use another variant of toMap() method that takes the third argument as the merge function which is used to resolve collisions between values associated with the same key.
๐ŸŒ
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
private Map<String, Choice> toMap(List books) { final Map hashMap = new HashMap<>(); for (final Book book : books) { hashMap.put(book.getISBN(), book); } return hashMap; } You can see we have iterated through the List using enhanced for loop of Java 5 and put each element into a HashMap, where ISBN code is the key, and the book object itself is the value. This is the best way to convert a List to Map in pre-JDK 8 worlds. It's clear, concise, and self-explanatory, but iterative. Now, let's see how we can do the same in Java 8 by using lambda expression and Stream API, here is my first attempt:
๐ŸŒ
Reverse Coding
reversecoding.net โ€บ java-8-list-to-map
Java 8 Stream - From List to Map | Reverse Coding
June 4, 2016 - We just need to change the two parameters of the Collectors.toMap, by specifying: //Name as key person -> person.getName() //Age as value person -> person.getAge(); ... List<Person> people = Arrays.asList( new Person("mario@reversecoding.net", "Mario", 27), new Person("luigi@reversecoding.net", "Luigi", 30), new Person("steve@reversecoding.net", "Steve", 20) ); Map<String, Integer> mapNameAge = people.stream() .collect(Collectors.toMap(person -> person.getName(), person -> person.getAge())); System.out.println(mapNameAge); //{Steve=20, Luigi=30, Mario=27}
๐ŸŒ
Medium
medium.com โ€บ geekculture โ€บ java-streams-collect-to-map-of-lists-with-grouping-by-8cb309df4598
Java Streams: Collect to Map of Lists with Grouping By | Geek Culture
May 7, 2022 - How to collect a stream into a map of lists, to avoid duplicate key exception, using the Collectors . groupingBy method method reference lambda functions
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java collections โ€บ converting list to map with a custom supplier
Converting List to Map With a Custom Supplier | Baeldung
November 13, 2025 - In this tutorial, weโ€™re going to convert a List<E> into a Map<K, List<E>>. Weโ€™ll achieve this with Javaโ€™s Stream API and the Supplier functional interface.
๐ŸŒ
JRebel
jrebel.com โ€บ blog โ€บ using-java-stream-map-and-java-stream-filter
Using Java 8 Stream Map and Java 8 Stream Filter | JRebel
June 25, 2025 - Further in this post we'll show how to filter a list or set a Java 8 stream filter and how to convert a stream to a regular set or a list.Back to top ยท The new java.util.stream package has been added to JDK which allows us to perform filter/map/reduce-like operations with the Java 8 collections stream.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java collections โ€บ java map โ€บ flatten a stream of maps to a single map in java
Flatten a Stream of Maps to a Single Map in Java | Baeldung
July 6, 2024 - Using streams, we can seamlessly convert a list of maps into a single map. This process involves streaming the list, flattening the entries of each map, and then collecting them into a single map using the Collectors.toMap() method.
๐ŸŒ
Medium
medium.com โ€บ @kiarash.shamaii โ€บ list-map-vs-stream-map-in-java-44440284386
Medium
August 28, 2024 - what is different between list.map and stream().map.collect() in java? In Java, both forEach on a list and the Stream API provide ways to iterate over collections, but they have some key differences: Direct Iteration: forEach is a method available on the Iterable interface (inherited by List), allowing you to iterate through the elements directly.