I need to store the following data in a format so that it can be sorted by the Double value from the lowest value to the highest. I do not know java very well at all.
Index, Value
"string1", 1.1134
"string2", 2.3469
"string4", 5.2365
"string3", 2.5597
...
I understand I can't use arrays for this. So there are things like ArrayLists, Comparators, Maps, HashMaps and I can't find any similar example to follow with them.
This post (Sort a two dimensional array based on one column) seems close, but I don't understand how it works.
Notes:
- I will not know the elements ahead of time, so I wanted to dimension the array at runtime. I hope the design can implement something like "new 2D-ArrayThingy[ExternalArray.size]"
- I will obtain all the elements, row by row, in a object based loop. They will always be string followed by double. So understanding how to populate the rows, one at a time is useful. I don't care if the order is string first or not.
Sub-Questions:
- How to I store this data per my needs?
- How do I sort the data by the doubles values?
- How do I output the data (to screen for example)?
TIA!