Java List Range getRange(List list, int start)

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

Description

Gets all elements from a list starting from the given index.

License

Open Source License

Parameter

Parameter Description
list the List
start the start index
T the list type

Return

the sublist of all elements from index start and on; empty list if the start index exceeds the list's size

Declaration

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

Method Source Code


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

import java.util.ArrayList;
import java.util.List;

public class Main {
    /**// ww  w  .  ja va  2s. c om
     * Gets all elements from a list starting from the given index.
     *
     * @param list the List
     * @param start the start index
     * @param <T> the list type
     * @return the sublist of all elements from index {@code start} and on; empty list
     *         if the start index exceeds the list's size
     */
    public static <T> List<T> getRange(List<T> list, int start) {
        if (start >= list.size()) {
            return new ArrayList<>();
        }
        return list.subList(start, list.size());
    }
}

Related

  1. getRange(List numbers)
  2. getRange(List list, int start, int count)