Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.List;

public class Main {

    public static <T> List<T> limit(List<T> list, Integer start, Integer numberOfRecords) {
        if (start != null && numberOfRecords != null && start >= 0 && numberOfRecords >= 0) {
            int indexFrom = start;
            int indexTo = start + numberOfRecords;
            if (indexFrom > list.size()) {
                indexFrom = list.size();
            }
            if (indexTo > list.size()) {
                indexTo = list.size();
            }
            return list.subList(indexFrom, indexTo);
        } else {
            return list;
        }
    }
}