Question: Currently I'm using an ArrayList to store a list of elements, whereby I will need to insert new elements at specific positions. There is a need for me to enter elements at a position larger than the current size. For e.g:

```
ArrayList<String> arr = new ArrayList<String>();
arr.add(3,"hi");

```

Now I already know there will be an OutOfBoundsException. Is there another way or another object where I can do this while still keeping the order? This is because I have methods that finds elements based on their index. For e.g.:

```
ArrayList<String> arr = new ArrayList<String>();
arr.add("hi");
arr.add(0,"hello");

```

I would expect to find "hi" at index 1 instead of index 0 now.   

So in summary, short of manually inserting null into the elements in-between, is there any way to satisfy these two requirements:

* Insert elements into position larger than current size
* Push existing elements to the right when I insert elements in the middle of the list

I've looked at [Java ArrayList add item outside current size](https://stackoverflow.com/questions/8925128/java-arraylist-add-item-outside-current-size), as well as HashMap, but HashMap doesn't satisfy my second criteria. Any help would be greatly appreciated.  

P.S. Performance is not really an issue right now.

UPDATE: There have been some questions on why I have these particular requirements, it is because I'm working on operational transformation, where I'm inserting a set of operations into, say, my list (a math formula). Each operation contains a string. As I insert/delete strings into my list, I will dynamically update the unapplied operations (if necessary) through the tracking of each operation that has already been applied. My current solution now is to use a subclass of ArrayList and override some of the methods. I would certainly like to know if there is a more elegant way of doing so though.

Answer: 
even you can use TreeMap for maintaining order of keys.
Use Vector class to solve this issue.

Vector vector = new Vector();
**vector.setSize(100);**

vector.set(98, "a");

When "setSize" is set to 100 then all 100 elements gets initialized with null values.