Here you can find the source of subList(List
Parameter | Description |
---|---|
T | type. |
list | the list. |
start | the start index. |
max | the max number of items to return. |
public static <T> List<T> subList(List<T> list, int start, int max)
//package com.java2s; import java.util.List; public class Main { /**//ww w . j av a2s . c o m * Returns the sub list of the given list avoiding exceptions, starting on * the given start index and returning at maximum the given max number of items. * * @param <T> type. * @param list the list. * @param start the start index. * @param max the max number of items to return. * @return sublist of the given list with the elements at the given indexes. */ public static <T> List<T> subList(List<T> list, int start, int max) { if (list == null) { return null; } int end = start + max; return list.subList(Math.max(0, start), Math.min(list.size(), end)); } }