Q:

How to remove element from ArrayList without left shifting the rest of elements

When you remove an element from an array list (arrayList.remove(int n)) it automatically shifts all the remaining elements to the left.
I was wondering is it possible for the elements to keep their position. So for example, if element at position 2 gets deleted, I want element at position 3 to remain where it is, not move to position 2. Thanks

A:

list.set(2, null);

This just replaces the element at index 2 with null, which leads to the desired result.

