Java Utililty Methods List Sub List

List of utility methods to do List Sub List

Description

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

Method

ListsubList(List list, int begin, int end)
Sublists the given list.
List<K> temp = new ArrayList<>(end - begin);
for (int i = begin; i <= end; i++) {
    temp.add(list.get(i));
return temp;
ListsubList(List lst, Collection indices)
Create a sub list with just these indices
List<T1> sublst = new ArrayList<>();
for (Integer idx : indices)
    sublst.add(lst.get(idx));
return sublst;
List>subList(List initial, int threshold)
creates a list of lists, each of which is up to the value of threshold in length.
ArrayList<List<T>> list = new ArrayList<List<T>>();
if (initial != null) {
    if (initial.size() <= threshold) {
        list.add(initial);
    } else {
        int factor = initial.size() / threshold;
        for (int i = 0; i < (factor + 1); i++) {
            list.add(limit(initial, i * threshold, threshold));
...
ListsubList(List input, int startIndex, int count)
Calculates the substring of a list based on a 1 based start index never exceeding the bounds of the list.
int fromIndex = startIndex - 1;
int toIndex = fromIndex + count;
if (toIndex >= input.size()) {
    toIndex = input.size();
if (fromIndex >= toIndex) {
    return Collections.emptyList();
return input.subList(fromIndex, toIndex);
ListsubList(List input, int startIndex, int count)
Calculates the substring of a list based on a 1 based start index never exceeding the bounds of the list.
int fromIndex = startIndex - 1;
int toIndex = fromIndex + count;
if (toIndex >= input.size()) {
    toIndex = input.size();
return input.subList(fromIndex, toIndex);
ListsubList(List it, int offset, int limit)
sub List
if (it == null) {
    return it;
if (it.size() <= offset) {
    return Collections.emptyList();
if (limit < 0) {
    limit = it.size();
...
Listsublist(List l, int fromIndex, int toIndex)
sublist
if (fromIndex > toIndex) {
    return Collections.<T>emptyList();
return l.subList(fromIndex, toIndex + 1);
ListsubList(List list, int fromIndex, int toIndex)
Gets a list containing all elements from the given index to the given index.
List<T> result = new ArrayList<T>();
if (list == null) {
    return result;
for (int i = fromIndex; i < toIndex; i++) {
    result.add(list.get(i));
return result;
...
ListsubList(List list, int fromIndex, int toIndex)
This operation exists because GWT doesn't support List.subList as of release 1.5 RC1.
ArrayList<T> ret = new ArrayList<T>();
for (int i = fromIndex; i < toIndex; i++) {
    ret.add(list.get(i));
return ret;
ListsubList(List list, int size)
Extract n items from the list, if the n>list.size, return all.
if (size >= list.size())
    return list;
List<T> res = new ArrayList<T>();
int alpha = -2 * (size - list.size() - 1) / (size * (size - 1));
int index = 0;
for (int i = 0; i < size; i++) {
    if (index >= list.size())
        return res;
...