I'm designing a system which needs a specific collection, it is written in Java. I need to store the history of prices of stock (dates and time).
One stock can have multiple dates and times as I want to show the previous prices.
Which collection would I use to map a stock id to multiple dates AND times?
I know there are HashTables, but I can't see how they will work as they still take only a key and a value. I have a stock class, within it I want a collection which takes and a value and a value.
One option would be using google guava multi-map (If you are ok to include third party jars).
multi-map allows you to add elements with same key.
Here is simple tutorial.
EDIT:
If not allowed to use guava, then another option would be:
HashMap<String, ArrayList<Stock>> map = HashMap<String, ArrayList<Stock>>()
Here Stock is simple POJO class with timeStamp and stock symbol.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With