Java Utililty Methods List Slice

List of utility methods to do List Slice

Description

The list of methods to do List Slice are organized into topic(s).

Method

Listslice(List as, int start, int end)
slice
return as.subList(start, end);
Listslice(List c, int fromIndex, int toIndex)
Returns a sub list with the provided indices.
List<T> result = new ArrayList<T>();
if (c == null) {
    return result;
int len = c.size();
if (fromIndex > len || toIndex > len || fromIndex < -len || toIndex < -len) {
    throw new IndexOutOfBoundsException("fromIndex or toIndex out of bounds");
if (len > 0 && fromIndex >= len) {
    throw new IndexOutOfBoundsException("fromIndex or toIndex out of bounds");
if (fromIndex < 0) {
    fromIndex += len;
if (toIndex < 0) {
    toIndex += len + 1;
} else if (toIndex == 0 && len > 0 || toIndex > 0) {
    toIndex++;
return new ArrayList<T>(c.subList(fromIndex, toIndex));
Listslice(List list, int index, int count)
slice
List<T> result = new ArrayList<T>();
if (index >= 0 && index < list.size()) {
    int end = index + count < list.size() ? index + count : list.size();
    for (int i = index; i < end; i++) {
        result.add(list.get(i));
return result;
...
Listslice(List list, int start, int end)
slice
List<T> sliced = new ArrayList<>();
for (int i = start; i < end && i < list.size(); i++) {
    sliced.add(list.get(i));
return sliced;
Listslice(List list, Integer start, Integer stop)
Slices a list, Python style
int size = list.size();
if (start == null) {
    start = 0;
} else if (start < 0) {
    start = size + start;
if (stop == null) {
    stop = size;
...
ListsliceList(final List list, final long offset, final int limit)
slice List
checkList(list, Integer.MAX_VALUE);
int len = list.size();
if (offset > len) {
    return new ArrayList<Long>(0);
return list.subList((int) offset, min((int) (offset + limit), len));
ArrayListsliceListByIndices(final List indices, final List list)
Given a list of indices into a list, return those elements of the list with the possibility of drawing list elements multiple times
ArrayList<T> subset = new ArrayList<T>();
for (int i : indices) {
    subset.add(list.get(i));
return subset;
List>slices(List list, int step)
slices
return slices(list, 0, list.size(), step);