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

StringaddRemoveChangeToString(int from, int to, List list, List removed)
add Remove Change To String
StringBuilder b = new StringBuilder();
if (removed.isEmpty()) {
    b.append(list.subList(from, to));
    b.append(" added at ").append(from);
} else {
    b.append(removed);
    if (from == to) {
        b.append(" removed at ").append(from);
...
booleancanMoveUp(List list, int[] indices)
checks whether the selected items can be moved up.
boolean result;
result = false;
if (indices.length > 0) {
    if (indices[0] > 0)
        result = true;
return result;
StringgetLongestLine(String text, List partsToRemove, String separator)
get Longest Line
String result = null;
String toInvestigate = removeParts(text, partsToRemove);
String longest = "";
String words[] = toInvestigate.split(separator);
for (int i = 0; i < words.length; i++) {
    String word = words[i];
    if (word.length() > longest.length()) {
        longest = word;
...
ListgetRemoveAll(List list1, Collection list2)
Return list1 - list2.
Set<E> set1 = new LinkedHashSet<E>(list1);
set1.removeAll(list2);
return new ArrayList<E>(set1);
Listminus(List initialList, List elementsToRemove)
minus
List<T> minusedList = new ArrayList<T>(initialList);
minusedList.removeAll(elementsToRemove);
return minusedList;
voidmove(List aList, int anIndex1, int anIndex2)
Moves the object at index 1 to index 2.
if (anIndex1 < 0 || anIndex1 >= aList.size() || anIndex2 < 0 || anIndex2 >= aList.size())
    return;
Object obj = aList.remove(anIndex1);
aList.add(anIndex2, obj);
voidmove(List collection, int indexToMoveFrom, int indexToMoveAt)
move
if (indexToMoveAt >= indexToMoveFrom) {
    Collections.rotate(collection.subList(indexToMoveFrom, indexToMoveAt + 1), -1);
} else {
    Collections.rotate(collection.subList(indexToMoveAt, indexToMoveFrom + 1), 1);
booleanmoveBackward(final List list, final int[] indices)
Moves elements specified by their indices backward by 1.
if (indices.length == 0)
    return false; 
Arrays.sort(indices);
if (indices[0] == 0)
    return false; 
for (final int idx : indices) {
    final T element = list.get(idx);
    list.set(idx, list.get(idx - 1));
...
booleanmoveBefore(List list, T element, T referenceElement)
Moves the given element before the reference element.
int index = list.indexOf(referenceElement);
if (index != -1) {
    list.remove(element);
    list.add(index, element);
    return true;
return false;
Listmoved(List old, List nu, Collection added, Collection removed)
moved
List<String> moved = null;
List<String> compare = null;
if (added != null) {
    for (String child : added) {
        if (compare == null) {
            compare = new ArrayList<String>(nu);
        compare.remove(child);
...