Browse - Programming Tips - How can I convert a HashMap into an ArrayList?

Date: 2015jan3
Language: java

Q.   How can I convert a HashMap into an ArrayList?

A.

If you have:

HashMap<String,Integer> h = new HashMap<String,Integer>();
To convert the keys into an ArrayList:
ArrayList<String> a = new ArrayList<String>(h.keySet());
To convert the values into an ArrayList:
ArrayList<Integer> a = new ArrayList<Integer>(h.values());