Java List Move Item move(List collection, int indexToMoveFrom, int indexToMoveAt)

Here you can find the source of move(List collection, int indexToMoveFrom, int indexToMoveAt)

Description

move

License

LGPL

Declaration

public static void move(List<?> collection, int indexToMoveFrom, int indexToMoveAt) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.util.Collections;
import java.util.List;

public class Main {
    public static void move(List<?> collection, int indexToMoveFrom, int indexToMoveAt) {
        if (indexToMoveAt >= indexToMoveFrom) {
            Collections.rotate(collection.subList(indexToMoveFrom, indexToMoveAt + 1), -1);
        } else {/*from w  ww . j  ava  2 s.  c  om*/
            Collections.rotate(collection.subList(indexToMoveAt, indexToMoveFrom + 1), 1);
        }
    }
}

Related

  1. canMoveUp(List list, int[] indices)
  2. getLongestLine(String text, List partsToRemove, String separator)
  3. getRemoveAll(List list1, Collection list2)
  4. minus(List initialList, List elementsToRemove)
  5. move(List aList, int anIndex1, int anIndex2)
  6. moveBackward(final List list, final int[] indices)
  7. moveBefore(List list, T element, T referenceElement)
  8. moved(List old, List nu, Collection added, Collection removed)
  9. moveDownItems(List list, int[] positions)