We can do it in a single line of code using java 8

List<Long> ids = viewValues.stream().map(ViewValue::getId).collect(Collectors.toList());

For more info : Java 8 - Streams

Answer from Radhakrishna on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ conversion-of-java-maps-to-list
Conversion of Java Map to List - GeeksforGeeks
July 11, 2025 - From Java 8, we can use the Stream API to make the conversion process even more easy and functional. 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.
๐ŸŒ
Roy Tutorials
roytuts.com โ€บ home โ€บ java โ€บ convert list of map objects into list of objects using java stream
Convert List of Map Objects Into List Of Objects Using Java Stream - Roy Tutorials
October 25, 2022 - List<Cd> cds = results.stream().map(m -> { Cd cd = new Cd(); cd.setId(Long.parseLong(String.valueOf(m.get("id")))); cd.setTitle(String.valueOf(m.get("title"))); cd.setArtist(String.valueOf(m.get("artist"))); return cd; }).collect(Collectors.toList()); In the above code snippets it is assumed that you have a POJO class Cd with id, title and artist attributes and corresponding getters/setters. It is also assumed that you also have created the required database table in the database server. Now the resultant List<Cd> cds can be used anywhere in the application. ... Soumitra is the founder of Roy Tutorials, sharing coding tutorials since 2014.
๐ŸŒ
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
๐ŸŒ
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
You can use this technique to convert ... a Map to a List in Java 8. You have learned how to convert a Map to the ArrayList and LinkedList. You have also learned how to create a List of Keys and a List of values, along with a list of entries from the Map object....
๐ŸŒ
Programiz
programiz.com โ€บ java-programming โ€บ examples โ€บ convert-map-list
Java Program to Convert Map (HashMap) to List
import java.util.*; public class MapList { public static void main(String[] args) { Map<Integer, String> map = new HashMap<>(); map.put(1, "a"); map.put(2, "b"); map.put(3, "c"); map.put(4, "d"); map.put(5, "e"); List<Integer> keyList = new ArrayList(map.keySet()); List<String> valueList = new ArrayList(map.values()); System.out.println("Key List: " + keyList); System.out.println("Value List: " + valueList); } }
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ java-convert-map-to-list
Java 8: How to Convert a Map to List
October 10, 2023 - 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. Streams work wonderfully with collections, and can aid us in converting a Map to a List. The easiest way to preserve the key-value mappings of a Map, while still converting it into a List would be to stream() the entries, which consist of the key-value pairs.
Find elsewhere
๐ŸŒ
Spring Framework Guru
springframework.guru โ€บ home โ€บ converting java map to list
Converting Java Map to List - Spring Framework Guru
June 25, 2019 - You use the values() method of Map to convert all the values of Map entries into a List.
๐ŸŒ
Mkyong
mkyong.com โ€บ home โ€บ java8 โ€บ java 8 โ€“ convert map to list
Java 8 โ€“ Convert Map to List | mkyong.com
May 24, 2017 - Few Java examples to convert a Map to a List Map map = new HashMap (); // Convert all Map keys to a List List result = new ArrayList(map.keySet()); //
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ java โ€บ examples โ€บ convert map (hashmap) to list
Java Program to Convert Map (HashMap) to List
December 12, 2024 - Start with a populated HashMap. Use the entrySet() method to get the set of entries. Stream the entries to convert each entry to a custom object or a string representation. ... import java.util.*;
๐ŸŒ
Makeinjava
makeinjava.com โ€บ home โ€บ convert list of objects to /from map in java 8 lambda stream (example)
Convert list of objects to /from map in java 8 lambda stream (with example)
January 3, 2024 - Given the list of person objects or POJO, convert list of objects to map and convert map to list of objects using java 8 lambda streams
๐ŸŒ
Java67
java67.com โ€บ 2015 โ€บ 01 โ€บ how-to-convert-map-to-list-in-java.html
How to convert a Map to List in Java? HashMap to ArrayList Example | Java67
As we have seen in how the get method of HashMap works, In Java, the equals() and hashcode() methods are an integral part of storing and retrieving objects from it. The map allows duplicate values but no duplicate keys. Map has its implementation in various classes like HashMap, ConcurrentHashMap, and TreeMap. The Map interface also 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. Now let's understand what is a List in Java, It is also an interface to provide an ordered collection based on an index.
๐ŸŒ
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 - Key in HashMap is just an add-on to find values, so you can just pick the values from Map and create a List out of it. The Map in Java also allows duplicate values which is fine with List which also allows duplicates but Map doesn't allow duplicate keys, this means you can use to store keys into a Set.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ java-program-to-convert-the-contents-of-a-map-to-list
Java program to convert the contents of a Map to list
To convert a map to list โˆ’ ยท Create a Map object. Using the put() method insert elements to it as key, value pairs ยท Create an ArrayList of integer type to hold the keys of the map.
๐ŸŒ
WsCube Tech
wscubetech.com โ€บ resources โ€บ java โ€บ programs โ€บ convert-map-to-list
Convert Map (HashMap) to List in Java: 5 Programs
1 month ago - Learn 5 easy ways to convert a Map or HashMap to a List in Java. Explore programs using constructors, entrySet(), lambda expressions, and more. Read now!
๐ŸŒ
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.