burntsugar burntsugar - 1 year ago 155
Java Question

Java: how to convert HashMap<String, Object> to array

I need to convert a

HashMap<String, Object>
to an array; could anyone show me how it's done?

Answer Source
 hashMap.keySet().toArray(); // returns an array of keys
 hashMap.values().toArray(); // returns an array of values


Should be noted that the ordering of both arrays may not be the same, See oxbow_lakes answer for a better approach for iteration when the pair key/values are needed.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download