I'd would like to use a collection of "key - value" pairs:
- Which is the base for a JTable data model (TableModel implementation), so I need to access elements by their index/position (e.g. to implement
Object getValueAt(int rowIndex, int columnIndex)
). The collection must preserve the order of the elements. An ArrayList would be good for that. - Which allows to retrieve elements by the value of the key. A HashMap would be good for that.
The closest usable collection I've found is LinkedHashMap. It preserves the order and allows retrieval by key. However the access to an item is not possible by index/position, I must iterate over the items until the good one is found. This is not be time-effective.
Is there a better one than this one? Thanks.
(Question is similar to this one, but the solution provided uses the conversion toArray()
which is not time-effective. If the set of pairs changes, the conversion needs to be done again.)