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 a Map instead. Specifically, if you use HashMap, it will also be O(1) - though it will be slower than ArrayList.
Map
O(1)
ArrayList