Eugene
Eugene

Reputation: 60244

What collection should I choose?

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 Map should I choose?

Upvotes: 1

Views: 107

Answers (3)

Maxym
Maxym

Reputation: 11906

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

Upvotes: 5

Xorty
Xorty

Reputation: 18861

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

Upvotes: 1

Bozho
Bozho

Reputation: 597402

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

Upvotes: 1

Related Questions