Java Utililty Methods List Move Item

List of utility methods to do List Move Item

Description

The list of methods to do List Move Item are organized into topic(s).

Method

voidmoveDownItems(List list, int[] positions)
move Down Items
for (int i = positions.length - 1; i >= 0; i--) {
    moveDownItem(list, positions[i]);
ObjectmoveElementInList(List list, int targetIndex, int sourceIndex)
Moves the object at the source index of the list to the _target index of the list and returns the moved object.
if (targetIndex >= list.size() || targetIndex < 0)
    throw new IndexOutOfBoundsException("targetIndex=" + targetIndex + ", size=" + list.size()); 
if (sourceIndex >= list.size() || sourceIndex < 0)
    throw new IndexOutOfBoundsException("sourceIndex=" + sourceIndex + ", size=" + list.size()); 
Object object = list.get(sourceIndex);
if (targetIndex != sourceIndex) {
    list.remove(sourceIndex);
    list.add(targetIndex, object);
...
ListmoveElementToIndex(List list, ELEMENT fromElement, ELEMENT toElement)
move Element To Index
assertObjectNotNull("list", list);
final int fromIndex = list.indexOf(fromElement);
final int toIndex = list.indexOf(toElement);
return moveElementToIndex(list, fromIndex, toIndex);
booleanmoveInList(List list, int index, T listItem)
Move the element of the list from its current location to the specified index.
boolean moved = list.remove(listItem);
if (moved) {
    list.add(index, listItem);
return moved;
voidmoveItem(List list, Object oldItem, int newIndex)
move Item
if ((list == null) || (list.isEmpty())) {
    return;
int index = list.indexOf(oldItem);
if (index == -1) {
    return;
list.remove(index);
...
ListmoveItemIdInSecond(final List list)
move Item Id In Second
final boolean noItemKind = moveItemKindInFirst(list);
if (list.contains("dmap.itemid")) {
    if (list.size() > 1) {
        list.remove("dmap.itemid");
        int index = 1;
        if (noItemKind) {
            index = 0;
        list.add(index, "dmap.itemid");
return list;
int[]moveItems(List list, int[] indices, int moveby, boolean up)
moves the selected items by a certain amount of items in a given direction.
int i;
int newIndex;
if (up) {
    for (i = 0; i < indices.length; i++) {
        if (indices[i] == 0)
            continue;
        newIndex = indices[i] - moveby;
        swap(list, indices[i], newIndex);
...
ListmoveLeft(int offset, T element, List list)
This method returns a new List instance containing the same element objects as the provided list, but with the specified element having been moved left by the specified offset.
return moveRight(-offset, element, list);
ListmoveOnePositionUp(final List list, final T object)
Move one position up.
return changePosition(list, object, -1);
ListmoveRight(int offset, T element, List list)
This method does the same as #moveLeft(int,Object,List) but it moves the specified element to the right instead of the left.
final int elementIndex = list.indexOf(element);
if (elementIndex == -1) {
    throw new NoSuchElementException("Element not found in provided list.");
if (offset == 0) {
    return list;
} else {
    int newElementIndex = elementIndex + offset;
...