我想知道Java HashMap和JSONObject的性能.
It seems JSONObject stores data internally using HashMap. But JSONObject might have additional overhead compared to HashMap.
Does any one know about the performance of Java JSONObject compared to HashMap?
谢谢
我想知道Java HashMap和JSONObject的性能.
It seems JSONObject stores data internally using HashMap. But JSONObject might have additional overhead compared to HashMap.
Does any one know about the performance of Java JSONObject compared to HashMap?
谢谢
As you said, JSONObject
is backed by a HashMap
.
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
.