Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Choosing the correct collection

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.

like image 859
John Vasiliou Avatar asked Feb 21 '26 02:02

John Vasiliou


1 Answers

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.

like image 52
kosa Avatar answered Feb 22 '26 16:02

kosa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!