List of usage examples for java.util List subList
List<E> subList(int fromIndex, int toIndex);
From source file:Main.java
public static <T> List<T> tail(List<T> col) { return col.isEmpty() ? col : col.subList(1, col.size()); }
From source file:Main.java
public static <T> List<T> limit(List<T> source, int size) { return new ArrayList<>(source.subList(0, size)); }
From source file:Main.java
public static <V> V[] subarray(V[] type, List<V> list, int from, int to) { return list.subList(from, to).toArray(type); }
From source file:Main.java
/** * * @param array the array to be converted into list * @param fromIndex the index of the first element, inclusive, to be sorted * @param toIndex the index of the last element, exclusive, to be sorted * @return//from ww w . ja v a2 s . c om */ public static <E> List<E> toList(E[] array, int fromIndex, int toIndex) { List<E> list = Arrays.asList(array); return list.subList(fromIndex, toIndex); }
From source file:Main.java
public static String[] subarray(List<String> list, int from, int to) { return list.subList(from, to).toArray(new String[0]); }
From source file:Main.java
public static List<?> subList(List<?> list, int fromIndex, int toIndex) { return list.subList(fromIndex, toIndex); }
From source file:Main.java
public static <T> List<T> head(List<T> list, int n) { if (n <= list.size()) { return list.subList(0, n); } else {//w ww. j a v a 2 s . c om return list; } }
From source file:Main.java
public static void resize(List list, int newSize) { if (newSize < list.size()) { list.subList(newSize, list.size()).clear(); } else {/* w w w. j a v a 2 s.c o m*/ list.addAll(Collections.nCopies(newSize - list.size(), null)); } }
From source file:Main.java
/** * Shift object to the bottom of list/*w w w. j a v a 2s . c o m*/ * * @param list list * @param index object index */ public static void shiftItemToBack(List<?> list, int index) { if (index >= 0) { Collections.rotate(list.subList(0, index + 1), 1); } }
From source file:Main.java
/** * Shift object to the top of list// w w w . j a v a 2 s . c om * * @param list list * @param index object index */ public static void shiftItemToFront(List<?> list, int index) { if (index >= 0) { Collections.rotate(list.subList(index, list.size()), -1); } }