How to add an element to Array and shift indexes?

arrays, java

Solution

The most simple way of doing this is to use an `ArrayList<Integer>` and use the `add(int, T)` method.

List<Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(2);
list.add(3);
list.add(4);
list.add(5);
list.add(6);

// Now, we will insert the number
list.add(4, 87);

Problem

I need to add an element to Array specifying position and value. For example, I have Array ``` int []a = {1, 2, 3, 4, 5, 6}; ``` after applying `addPos(int 4, int 87)` it should be ``` int []a = {1, 2, 3, 4, 87, 5}; ``` I understand that here should be a shift of Array's indexes, but don't see how to implement it in code.

Original source