У меня есть массив объектов в Java, и я пытаюсь потянуть один элемент в начало и сместить остальные на один.
Предположим, у меня есть массив размером 10, и я пытаюсь вытащить пятый элемент. Пятый элемент переходит в положение 0
, и все элементы от 0 до 5 будут сбрасываться на один.
Этот алгоритм неправильно сдвигает элементы:
Object temp = pool[position];
for (int i = 0; i < position; i++) {
array[i+1] = array[i];
}
array[0] = temp;
Как мне это сделать правильно?