Java tutorial
//package com.java2s; import java.util.List; public class Main { /** * <p> * Get sub List form source list * </p> * * @param sourceList source list * @param fromIndex start index, if less than 0, start form 0 * @param toIndex end index, if large than sourceList.size(), ends with * sourceList.size() * @return */ public static <E extends Object> List<E> subList(List<E> sourceList, int fromIndex, int toIndex) { if (fromIndex > toIndex) { fromIndex = toIndex; } int endIndex = sourceList.size(); if (fromIndex > endIndex) { fromIndex = endIndex; } else if (fromIndex < 0) { fromIndex = 0; } if (toIndex > endIndex) { toIndex = endIndex; } return sourceList.subList(fromIndex, toIndex); } /** * <p> * Get sub List form source list * </p> * * @param sourceList source list, if less than 0, start form 0 * @param fromIndex start index * @return */ public static <E extends Object> List<E> subList(List<E> sourceList, int fromIndex) { return subList(sourceList, fromIndex, sourceList.size()); } }