Java examples for java.util:List Operation
rotates the item in list
//package com.java2s; import java.util.Collections; import java.util.List; public class Main { public static void main(String[] argv) { List list = java.util.Arrays.asList("asdf", "java2s.com"); int fromPos = 42; int toPos = 42; rotateInto(list, fromPos, toPos); }//from ww w . j a v a 2 s .c o m public static void rotateInto(List<?> list, int fromPos, int toPos) { boolean moveRight = toPos > fromPos; int fromIndex = moveRight ? fromPos : toPos; int toIndex = (moveRight ? toPos : fromPos) + 1; int distance = moveRight ? -1 : 1; // negative == backwards Collections.rotate(list.subList(fromIndex, toIndex), distance); } }