Osman Khalid
Osman Khalid

Reputation: 798

What java data structure should be appropriate here

I am very much new in java (but not to programming). I have to design a data structure, as indicated below. The columns are (dynamic and) identified by id (e.g. 77, 55, 67 etc). For each column, I can have dynamic entries in rows, but the entry "must be" following the order of insertion. Means when we retrieve, they should be output in the same order of insertion. After N entries, I want to delete the oldest entry, to control the list size.

MY QUESTION: What data structure (e.g. HashMap, ArrayList, Set etc) for columns and rows I should use for my problem in java.

data

Upvotes: 1

Views: 82

Answers (2)

fazhool
fazhool

Reputation: 121

It looks like a map of rows, and a row looks like a Map... meaning:

Map<Integer, LinkedHashMap<Integer, Double>> collection = new HashMap<Integer, LinkedHashMap<Integer, Double>>();

the LinkedHashMap will retain the order elements (LinkedHashMap is ordered, TreeMap is sorted, HashMap is none).

Upvotes: 3

Luchian Grigore
Luchian Grigore

Reputation: 258558

It looks like you're looking for a Queue

Upvotes: 2

Related Questions