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

List>split(List from, int subListSize)
Partition from into subLists, each of size subListSize.
List<List<T>> into = new ArrayList<List<T>>();
for (int first = 0; first < from.size(); first += subListSize) {
    into.add(from.subList(first, Math.min(first + subListSize, from.size())));
return into;
List>splitIntoSubListsByNumber(final List list, final int numberOfSublists)
split Into Sub Lists By Number
final int sizeOfSublists = (int) Math.ceil((double) list.size() / (double) numberOfSublists);
return splitIntoSubListsBySize(list, sizeOfSublists);
List>splitList(List list, int subListNumber)
Methode permettant de splitter une liste en un certain nombre de sous-listes
List<List<T>> splitted = new ArrayList<List<T>>();
if (list == null || list.size() == 0)
    return splitted;
int listSize = list.size();
int subSize = Math.max(listSize / (subListNumber - 1), 1);
for (int i = 0; i < listSize; i += subSize) {
    splitted.add(new ArrayList<T>(list.subList(i, Math.min(listSize, i + subSize))));
return splitted;
List>splitListToSubLists(List parentList, int subListSize)
split List To Sub Lists
List<List<T>> subLists = new ArrayList<List<T>>();
if (subListSize > parentList.size()) {
    subLists.add(parentList);
} else {
    int remainingElements = parentList.size();
    int startIndex = 0;
    int endIndex = subListSize;
    do {
...
booleanstartsWith(final List list, final List subList)
Does a list start with a sub-list.
if ((list == null) || (subList == null) || (list.size() < subList.size())) {
    return false;
return list.subList(0, subList.size()).equals(subList);
Listsub(List l, int index)
sub
List<T> subL = new ArrayList<>(l);
subL.remove(index);
return subL;
booleansubArray(List listA, List listB)
Sub array.
if (isEmpty(listA) && !isEmpty(listB)) {
    return false;
if (!isEmpty(listA) && isEmpty(listB)) {
    return false;
if (isSizeZero(listA) && isSizeZero(listB)) {
    return true;
...
ListsubList(final Iterable

parent, final Iterable child)
Create sublist view of child from element on [size-of-parent] position to last element.

Iterator<P> iParent = parent.iterator();
List<C> result = new ArrayList<>();
for (C arg : child) {
    if (iParent.hasNext()) {
        iParent.next();
    } else {
        result.add(arg);
if (iParent.hasNext()) {
    throw new IllegalArgumentException("Parent argument is bigger than child.");
return result;
ListsubList(final List oriList, int[] indexes)
Copies the elements at the indexes positions
List<E> list = new ArrayList<E>(indexes.length);
for (int index : indexes) {
    if (index >= 0 && index < oriList.size()) {
        list.add(oriList.get(index));
return list;
ListsubList(final List list, final int first, final int count)
a sublist implementation that is diffrent from List#subList(int,int) as it handles out of bounds indexes gracefully
if (list.size() < first) {
    return new ArrayList<T>(0);
return list.subList(first, Math.min(first + count, list.size()));