Java List Sub List subList(List input, int startIndex, int count)

Here you can find the source of subList(List input, int startIndex, int count)

Description

Calculates the substring of a list based on a 1 based start index never exceeding the bounds of the list.

License

Apache License

Parameter

Parameter Description
input a parameter
startIndex a parameter
count a parameter

Declaration

public static <T> List<T> subList(List<T> input, int startIndex,
        int count) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.List;

public class Main {
    /**//from  w  w  w . ja va  2  s  .co  m
     * Calculates the substring of a list based on a 1 based start index never exceeding
     * the bounds of the list. 
     * @param input
     * @param startIndex
     * @param count
     * @return
     */
    public static <T> List<T> subList(List<T> input, int startIndex,
            int count) {
        int fromIndex = startIndex - 1;
        int toIndex = fromIndex + count;
        if (toIndex >= input.size()) {
            toIndex = input.size();
        }
        return input.subList(fromIndex, toIndex);
    }
}

Related

  1. subList(List list, int start, int end)
  2. subList(List list, int begin, int end)
  3. subList(List lst, Collection indices)
  4. subList(List initial, int threshold)
  5. subList(List input, int startIndex, int count)
  6. subList(List it, int offset, int limit)
  7. sublist(List l, int fromIndex, int toIndex)
  8. subList(List list, int fromIndex, int toIndex)
  9. subList(List list, int fromIndex, int toIndex)