正确截取List指定位置的内容
正确截取List指定位置的内容
import java.util.ArrayList;
import java.util.List;
public class ListUtils {
public static <T> List<T> getSubList(List<T> list, int fromIndex, int toIndex) {
//list.stream().limit(toIndex);
if (toIndex > list.size()) {
}
List listClone = list;
List sub = listClone.subList(fromIndex, toIndex);
List two = new ArrayList(sub);
sub.clear(); // since sub is backed by one, this removes all sub-list items from one
return two;
}
}