开发者

Is it more efficient to serialize a Map or List of objects in java?

开发者 https://www.devze.com 2022-12-31 20:43 出处:网络
Or maybe there is no difference? The data is the same, because I need to save a Key-Valu开发者_运维问答e, so in case of the list I will have to implement KeyValue structure and put it into the list.I

Or maybe there is no difference? The data is the same, because I need to save a Key-Valu开发者_运维问答e, so in case of the list I will have to implement KeyValue structure and put it into the list.


I would think it's less work to serialize a list, since they have less to keep track of than a map, but I wouldn't worry about it. If you need to use a map in your program, use a map, and serialize whatever data structure you're using to store your data. You shouldn't choose your data structure based on ease of serialization, it's going to be negligible


Efficiency is the same. Except that a map holds keys and data, so it has twice the data to serialize.

But the big oh (O(n)) stays the same. Use whatever data structure fits best in your application because the difference wont matter in the long run.


If you want a more efficient serialization, I suggest you use a different serialization like hessian.

0

精彩评论

暂无评论...
验证码 换一张
取 消