Here you can find the source of limit(List
public static <T> List<T> limit(List<T> list, Long firstResult, Long maxResults)
//package com.java2s; //License from project: Open Source License import java.util.List; public class Main { public static <T> List<T> limit(List<T> list, Long firstResult, Long maxResults) { return limit(list, firstResult != null ? firstResult.intValue() : null, maxResults != null ? maxResults.intValue() : null); }// w w w . java2 s. c om public static <T> List<T> limit(List<T> list, Integer firstResult, Integer maxResults) { int resultCount = list.size(); int firstIndex = firstResult == null ? 0 : Math.min(firstResult.intValue(), resultCount); int toIndex = maxResults == null ? resultCount : Math.min(firstIndex + maxResults.intValue(), resultCount); return list.subList(firstIndex, toIndex); } }