I know that I cannot store a value at an index of an ArrayList that hasn\'t been used yet, i.e. is less than the size. In other words, if myArrayList.size() is 5, then if I
You can use TreeMap, which is sorted in natural order by the value.
TreeMap
value
Here you can keep value as the index. You can insert any value, it need not be in order. This seems the simplest solution.