Java: how to convert HashMaplt;String, Objectgt; to array(Java:如何转换HashMaplt;String、Objectgt;排列)
问题描述
我需要将 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>排列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Java:如何转换HashMap<String、Object>排列


基础教程推荐
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01