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> truncateList(List<T> lst, int maxTrainDocs) { if (maxTrainDocs < lst.size()) { return lst.subList(0, maxTrainDocs); }/*from w ww. j a va 2 s .c o m*/ return lst; }
From source file:Main.java
public static <T> List<T> popSubList(List<T> originList, int fromIndex, int toIndex) { List<T> subList = originList.subList(fromIndex, toIndex); List<T> result = new ArrayList<T>(subList); subList.clear();/*from www .ja va 2 s. c o m*/ return result; }
From source file:Main.java
public static <T> List<T> subList(List<T> list, int fromIndex, int toIndex) { if (list == null) return null; return list.subList(fromIndex, Math.min(list.size(), toIndex)); }
From source file:com.shirokumacafe.archetype.common.utilities.RandomData.java
/** * list?n./*from ww w. j a va 2 s.c om*/ */ public static <T> List<T> randomSome(List<T> list, int n) { Collections.shuffle(list); return list.subList(0, n); }
From source file:Main.java
public static <K, V> List<K> keyToList(Map<K, V> map, int count) { if (isNotNull(map)) { if (map.size() <= count) { return new ArrayList<K>(map.keySet()); } else {//from w w w . ja v a 2s .c o m List<K> list = new ArrayList<K>(map.keySet()); return list.subList(0, count); } } return null; }
From source file:Main.java
/** * Returns sub list with copied values.// ww w .j a va 2 s . co m * * @param list source list * @param fromIndex start index * @param toIndex end index * @param <T> data type * @return sub list with copied values */ public static <T> ArrayList<T> copySubList(final List<T> list, final int fromIndex, final int toIndex) { return new ArrayList<T>(list.subList(fromIndex, toIndex)); }
From source file:Main.java
public static <T> List<T> range(List<? extends T> list, T min, T max, Comparator<? super T> comparator) { List<T> tList = newArrayList(); addAll(list, tList);//w w w.ja v a2 s . c o m tList.sort(comparator); return tList.subList(indexOf(list, min), indexOf(list, max) + 1); /* return list.stream() .sorted(comparator) .filter(t -> comparator.compare(t,min)>=0&&comparator.compare(t,max)<=0) .collect(Collectors.toList()); */ }
From source file:Main.java
/** * Sub the list without exception//w ww . j a v a 2 s .c o m */ public static <T> List<T> safeSubList(List<T> list, int start, int end) { if (start >= list.size()) { return Collections.emptyList(); } return list.subList(start, Math.min(end, list.size())); }
From source file:Main.java
public static <T> List<T> subList(List<T> target, int size) { if (target.size() <= size) { return new ArrayList<T>(target); } else {//from w ww .java2s. c om return target.subList(0, size); } }
From source file:Main.java
public static void move(List<?> collection, int indexToMoveFrom, int indexToMoveAt) { if (indexToMoveAt >= indexToMoveFrom) { Collections.rotate(collection.subList(indexToMoveFrom, indexToMoveAt + 1), -1); } else {/* www . j av a 2 s .c o m*/ Collections.rotate(collection.subList(indexToMoveAt, indexToMoveFrom + 1), 1); } }