A map is a collection of key-value pairs of elements, whereas a list is simply a sequence of elements. To convert a map to a list, we have three options.

  • We can have a list of keys from the map using Map.keySet, which returns a Set<K>
  • We can have a list of values from the map using Map.valueSet, which returns a Collection<V>
  • We can have a list of all the entries (as compound values of key-value pairs) from the map using Map.entrySet, which returns key-value pairs marked by Map.Entry<K,V> interface

An ArrayList has overloaded constructors which can take in either a Set or a Collection. Since above-mentioned ways either return a Set or a Collection, we can just pass the return values to the relevant constructors. Here is an example:

If you fancy, we can also use java streams from the Java 8 feature set to convert map keys to a list. Since we can use streaming, so we can also make use of filter and other allied functions to manipulate contents of the list as it is being constructed. We can then collect the values using Collectors.

In conclusion, you have many options. I would suggest using the Java 8 one since it allows us to filter and apply other relevant functions.