Java List Sub List truncatedSubList(List inList, int start, int end)

Here you can find the source of truncatedSubList(List inList, int start, int end)

Description

Gets a sublist of a list, truncated at the end of the list if too many elements are selected.

License

Open Source License

Declaration

public static <T> List<T> truncatedSubList(List<T> inList, int start,
        int end) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.List;

public class Main {
    /**/*from  w w w .  j  a  v  a  2 s .c  o m*/
     * Gets a sublist of a list, truncated at the end of the list if too many elements are selected.
     * This behaves exactly like List.subList, including all notes in its Javadoc concerning
     * structural modification of the backing List, etc. with one difference: if the end index is
     * beyond the end of the list, instead of throwing an exception, the sublist simply stops at the
     * end of the list.  After the fifth or so time writing this idiom, it seems worth having a
     * function for. :-)
     */
    public static <T> List<T> truncatedSubList(List<T> inList, int start,
            int end) {
        // List.sublist will do our error checking for us
        final int limit = Math.min(end, inList.size());
        return inList.subList(start, limit);
    }
}

Related

  1. subList(List src, int preBatchCount)
  2. subList(List list, int start, int end)
  3. subListByStartAndEnd( List list, M start, M end)
  4. subListMaxSize(List list, int maxSize)
  5. subListPage(List baseList, int fromIndex, int maxPageSize)