I have an ArrayList and I need to make sure a specific item is at the 0 position and if it is not, I need to move it there. The item has an isStartIte
There are 2 ways of moving an item to the desired position in the ArrayList.
1. Swap the items
Collections.swap(myArray, i, 0);
--> Here position "i" will be moved to 0th position and all the other items in between this range will remain as it is.
2. Shift the items
myArray.add(0,myArray.remove(i))
--> Here item at position "i" will be removed and added to the 0th position. Here all the other items position will be shifted as you're adding a new item at 0.
Hope this will helps you to understand the difference between swap and shift the position. Use the solution according to your requirement.