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

ListgetSubList(List allKeys, String part)
get Sub List
int start = Integer.parseInt(part.split(":")[0]);
int end = Integer.parseInt(part.split(":")[1]);
if (end > allKeys.size()) {
    end = allKeys.size();
return allKeys.subList(start, end);
ListgetSubList(List list, int from, int maxnum)
get Sub List
if (list == null || list.size() <= from)
    return new ArrayList<T>();
return new ArrayList(list.subList(from, Math.min(from + maxnum, list.size())));
ListgetSublist(List list, int i)
get Sublist
List<T> sublist = new ArrayList<T>();
for (int j = i; j < list.size(); j++) {
    sublist.add(list.get(j));
return sublist;
ListgetSubList(List list, int start, int end)
get Sub List
List<T> subList = new ArrayList<T>();
int len = list.size();
if (start >= 0 && end > start && end <= len) {
    for (int i = start; i < end; ++i) {
        subList.add(list.get(i));
return subList;
...
ListgetSubList(List list, int start, int limit)
get Sub List
if (list == null || list.isEmpty()) {
    return new ArrayList<T>(0);
int listLength = list.size();
if (start > listLength - 1) {
    return new ArrayList<T>();
limit = start + limit > listLength ? listLength - start : limit;
...
ListgetSubListFromStart(List list, int length)
get Sub List From Start
List<T> listSub = null;
if (list != null) {
    length = list.size() > length ? length : list.size();
    listSub = list.subList(0, length);
return listSub;
ListgetSubListIndex(Object[] tofind, Object[] tokens)
If tofind is a part of tokens, it finds the starting index of tofind in tokens If tofind is not a sub-array of tokens, then it returns null note that tokens sublist should have the exact elements and order as in tofind
if (tofind.length > tokens.length)
    return null;
List<Integer> allIndices = new ArrayList<Integer>();
boolean matched = false;
int index = -1;
int lastUnmatchedIndex = 0;
for (int i = 0; i < tokens.length;) {
    for (int j = 0; j < tofind.length;) {
...
booleanisSubList(List l1, List l)
Returns true iff l1 is a sublist of l (i.e., every member of l1 is in l, and for every e1 < e2 in l1, there is an e1 < e2 occurrence in l).
Iterator<? super T> it = l.iterator();
for (T o1 : l1) {
    if (!it.hasNext()) {
        return false;
    Object o = it.next();
    while ((o == null && !(o1 == null)) || (o != null && !o.equals(o1))) {
        if (!it.hasNext()) {
...
intlastIndexOfSubList(final List list0, final List list1)
last Index Of Sub List
return Collections.lastIndexOfSubList(list0, list1);
List>slice(List stringList, int subListSize)
slice
List<List<String>> listOfSubLists = new ArrayList<>();
if (stringList != null) {
    int leftBoundary = 0;
    int rightBoundary = subListSize < stringList.size() ? subListSize : stringList.size();
    do {
        listOfSubLists.add(stringList.subList(leftBoundary, rightBoundary));
        leftBoundary = rightBoundary;
        rightBoundary = rightBoundary + subListSize < stringList.size() ? rightBoundary + subListSize
...