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.
精彩评论