Java:如何转换HashMap<String, Object>排列 [英] Java: how to convert HashMap&lt;String, Object&gt; to array

查看:31
本文介绍了Java:如何转换HashMap<String, Object>排列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将 HashMap 转换为数组;谁能告诉我它是怎么做的?

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>排列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆