Java HashMap vs JSONObject(Java HashMap 与 JSONObject)
问题描述
我想知道 Java HashMap 与 JSONObject 的性能.
I am wondering about the performance of Java HashMap vs JSONObject.
似乎 JSONObject 在内部使用 HashMap 存储数据.但与 HashMap 相比,JSONObject 可能会有额外的开销.
It seems JSONObject stores data internally using HashMap. But JSONObject might have additional overhead compared to HashMap.
有人知道Java JSONObject 与HashMap 相比的性能吗?
Does any one know about the performance of Java JSONObject compared to HashMap?
谢谢!
推荐答案
如你所说,JSONObject
由 HashMap
支持.
As you said, JSONObject
is backed by a HashMap
.
因此,性能几乎相同.JSONObject.get()
添加了一个空检查,如果没有找到一个键会抛出一个异常.JSONObject.put()
只是调用 map.put()
.
Because of this, performance will be almost identical. JSONObject.get()
adds a null check, and will throw an exception if a key isn't found. JSONObject.put()
just calls map.put()
.
因此,几乎没有开销.如果您正在处理 JSON 对象,您应该始终使用 JSONObject
而不是 HashMap
.
So, there is almost no overhead. If you are dealing with JSON objects, you should always use JSONObject
over HashMap
.
这篇关于Java HashMap 与 JSONObject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Java HashMap 与 JSONObject


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