Java – How to convert a Map to List in Java

collectionsjavalistmap

What is the best way to convert a Map<key,value> to a List<value>? Just iterate over all values and insert them in a list or am I overlooking something?

Best Answer

List<Value> list = new ArrayList<Value>(map.values());

assuming:

Map<Key,Value> map;