Java List Sub List slice(List stringList, int subListSize)

Here you can find the source of slice(List stringList, int subListSize)

Description

slice

License

Open Source License

Declaration

public static List<List<String>> slice(List<String> stringList, int subListSize) 

Method Source Code


//package com.java2s;
import java.util.ArrayList;

import java.util.List;

public class Main {
    public static List<List<String>> slice(List<String> stringList, int subListSize) {
        List<List<String>> listOfSubLists = new ArrayList<>();

        if (stringList != null) {
            int leftBoundary = 0;
            int rightBoundary = subListSize < stringList.size() ? subListSize : stringList.size();

            do {// ww  w . j  av  a 2s. c  o  m
                listOfSubLists.add(stringList.subList(leftBoundary, rightBoundary));

                leftBoundary = rightBoundary;
                rightBoundary = rightBoundary + subListSize < stringList.size() ? rightBoundary + subListSize
                        : stringList.size();
            } while (leftBoundary != rightBoundary);

            return listOfSubLists;
        }

        return listOfSubLists;
    }
}

Related

  1. getSubList(List list, int start, int limit)
  2. getSubListFromStart(List list, int length)
  3. getSubListIndex(Object[] tofind, Object[] tokens)
  4. isSubList(List l1, List l)
  5. lastIndexOfSubList(final List list0, final List list1)
  6. split(List from, int subListSize)
  7. splitIntoSubListsByNumber(final List list, final int numberOfSublists)
  8. splitList(List list, int subListNumber)
  9. splitListToSubLists(List parentList, int subListSize)