How to convert a Map to List in Java?

Javaa picture Javaa · Jun 22, 2009 · Viewed 735.8k times · Source

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?

Answer

cletus picture cletus · Jun 22, 2009
List<Value> list = new ArrayList<Value>(map.values());

assuming:

Map<Key,Value> map;