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 start, int end)
sub List
List<T> subList = new ArrayList<>();
for (int i = start; i < end; i++) {
    if (list.size() > i) {
        subList.add(list.get(i));
    } else {
        break;
return subList;
Listsublist(List list, int start, int limit)
Sub list
int fromIndex = Math.min(start, list.size());
int toIndex = Math.min(fromIndex + limit, list.size());
return list.subList(fromIndex, toIndex);
ListsubList(List list, int start, int max)
Returns the sub list of the given list avoiding exceptions, starting on the given start index and returning at maximum the given max number of items.
if (list == null) {
    return null;
int end = start + max;
return list.subList(Math.max(0, start), Math.min(list.size(), end));
ListsubList(List list, int[] indexs)
sub List
if (list == null || list.size() == 0) {
    return list;
if (indexs == null || indexs.length == 0) {
    return new ArrayList<T>(0);
List<T> result = new ArrayList<T>(indexs.length);
for (int index : indexs) {
...
ListsubList(List origin, int start, int length)
sub List
return origin.subList(start, start + length);
ListsubList(List parentList, int start, int end)
sub List
List<T> l = new ArrayList<T>();
for (int i = start; i < end; i++) {
    l.add(parentList.get(i));
return l;
ArrayListsubList(List query, int first, int max)
sub List
int to;
Iterator<T> e;
ArrayList<T> list;
if (query == null || query.isEmpty() || first >= query.size())
    return null;
to = Math.min(first + max, query.size());
list = new ArrayList<T>(to - first);
e = query.listIterator(first);
...
List[]subList(List src, int preBatchCount)
sub List
int count = src.size();
int batchCount = (count + preBatchCount - 1) / preBatchCount;
List[] result = new List[batchCount];
for (int index = 0; index < batchCount; ++index) {
    int begin = index * preBatchCount;
    int end = (index + 1) * preBatchCount;
    if (end > count) {
        end = count;
...
ListsubList(List list, int start, int end)
Returns a section of the given list.
List<X> temp = new ArrayList<X>();
for (int i = start; i < end; i++) {
    temp.add(list.get(i));
return temp;
ListsubListByStartAndEnd(List list, M start, M end)
sub List By Start And End
List<M> returnList = new ArrayList<M>();
for (M element : list) {
    if (element.compareTo(start) >= 0 && element.compareTo(end) <= 0) {
        returnList.add(element);
return returnList;