Java List Sub List subList(List list, int start, int max)

Here you can find the source of subList(List list, int start, int max)

Description

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.

License

Open Source License

Parameter

Parameter Description
T type.
list the list.
start the start index.
max the max number of items to return.

Return

sublist of the given list with the elements at the given indexes.

Declaration

public static <T> List<T> subList(List<T> list, int start, int max) 

Method Source Code

//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));
    }
}

Related

  1. subList(List list, int fromIndex, int toIndex)
  2. subList(List list, int fromIndex, int toIndex)
  3. subList(List list, int size)
  4. subList(List list, int start, int end)
  5. sublist(List list, int start, int limit)
  6. subList(List list, int[] indexs)
  7. subList(List origin, int start, int length)
  8. subList(List parentList, int start, int end)
  9. subList(List query, int first, int max)