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
list.set(2, null);
This just replaces the element at index 2 with null, which leads to the desired result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With