Java的:如何HashMap的&LT转换;弦乐,对象&gt;数组 [英] Java: how to convert HashMap<String, Object> to array
本文介绍了Java的:如何HashMap的&LT转换;弦乐,对象&gt;数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要转换的HashMap&LT;弦乐,对象&gt;
到一个数组;谁能告诉我它是如何做?
解决方案
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.
这篇关于Java的:如何HashMap的&LT转换;弦乐,对象&gt;数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文