Here you can find the source of moveUp(List
Parameter | Description |
---|---|
list | the specific list |
toMoveUp | the given ones to move up |
private static void moveUp(List<Object> list, List<Object> toMoveUp)
//package com.java2s; import java.util.ArrayList; import java.util.List; public class Main { private static void moveUp(List<Object> list, List<Object> toMoveUp) { // original list and its copy List<Object> listCopy = new ArrayList<Object>(list.size()); for (Object object : list) { listCopy.add(object);/*from www. ja v a 2 s. com*/ } list.clear(); // do move up int count = listCopy.size(); Object current = null; Object floating = null; for (int i = 0; i < count; i++) { current = listCopy.get(i); if (toMoveUp.contains(current)) { list.add(current); } else { if (floating != null) { list.add(floating); } floating = current; } } if (floating != null) { list.add(floating); } // clear copy of list listCopy.clear(); } }