开发者

What collection should I choose?

开发者 https://www.devze.com 2023-02-11 06:07 出处:网络
I need just a collection of two pairs of data, none of them is going to be null. I don\'t need any sorting or other possibilities. What implementation of M开发者_高级运维ap should I choose?Map Impleme

I need just a collection of two pairs of data, none of them is going to be null. I don't need any sorting or other possibilities. What implementation of M开发者_高级运维ap should I choose?


Map Implementations:

The three general-purpose Map implementations are HashMap, TreeMap and LinkedHashMap. If you need SortedMap operations or key-ordered Collection-view iteration, use TreeMap; if you want maximum speed and don't care about iteration order, use HashMap; if you want near-HashMap performance and insertion-order iteration, use LinkedHashMap. In this respect, the situation for Map is analogous to Set. Likewise, everything else in the Set Implementations section also applies to Map implementations


HashMap is usually the default choice. It gives one O(1) lookup.


HashMap is most commonly used for such Key-Value pairs.

0

精彩评论

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