Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//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 {
                listOfSubLists.add(stringList.subList(leftBoundary, rightBoundary));

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

            return listOfSubLists;
        }

        return listOfSubLists;
    }
}