Reputation: 798
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.
Upvotes: 1
Views: 82
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