本文介绍了Java:如何转换HashMap<String、Object>排列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将 HashMap<String, Object>
转换为数组;谁能告诉我它是怎么做的?
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
编辑
需要注意的是,两个数组的排列顺序可能不一样,当需要键/值对时,请参阅 oxbow_lakes 答案以获得更好的迭代方法.
Edit
It 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<String、Object>排列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!