更新时间:2023-11-18 08:26:46
hashMap.keySet()的toArray()。 //返回键阵列
。hashMap.values()的toArray(); //返回值的数组
修改
应当指出,这两个阵列的顺序可能是不一样的,
见oxbow_lakes答案为是需要对键/值时,迭代一个更好的方法。
I need to convert a HashMap<String, Object>
to an array; could anyone show me how it's done?
hashMap.keySet().toArray(); // returns an array of keys
hashMap.values().toArray(); // returns an array of values
Edit
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.