Java List Move Item moveUp(final List list, final T toMoveUp)

Here you can find the source of moveUp(final List list, final T toMoveUp)

Description

move Up

License

Apache License

Declaration

public static <T> boolean moveUp(final List<T> list, final T toMoveUp) 

Method Source Code


//package com.java2s;
/*/*from  w ww .  jav a  2 s  . c  o  m*/
 * Copyright 2016 Nokia Solutions and Networks
 * Licensed under the Apache License, Version 2.0,
 * see license.txt file for details.
 */

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

public class Main {
    public static <T> boolean moveUp(final List<T> list, final T toMoveUp) {
        boolean result = false;
        if (list.size() >= 2) {
            int elemIndex = list.indexOf(toMoveUp);
            if (elemIndex > 0) {
                Collections.swap(list, elemIndex, elemIndex - 1);
                result = true;
            }
        }

        return result;
    }
}

Related

  1. moveOnePositionUp(final List list, final T object)
  2. moveRight(int offset, T element, List list)
  3. moveRows(final List allRows, final List rowsToMove, final int index)
  4. moveToFront(List aList, Object anObj)
  5. moveTop(List list, int[] indices)
  6. moveUp(List list, List toMoveUp)
  7. moveUp(List list, int[] selectionIndexes)
  8. moveUpInList(List list, int... indices)
  9. moveUpInListSingleEntry(List list, int index)

  10. HOME | Copyright © www.java2s.com 2016