Here you can find the source of subList(final List
Parameter | Description |
---|---|
E | a parameter |
oriList | a parameter |
indexes | a parameter |
public static <E> List<E> subList(final List<E> oriList, int[] indexes)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { /**//w w w . j a va 2 s. c o m * Copies the elements at the indexes positions * * @param <E> * @param oriList * @param indexes * @return */ public static <E> List<E> subList(final List<E> oriList, int[] indexes) { List<E> list = new ArrayList<E>(indexes.length); for (int index : indexes) { if (index >= 0 && index < oriList.size()) { list.add(oriList.get(index)); } } return list; } /** * Copies all the elements form start (excluded) to end (included) * * @param <E> * @param oriList * @param start * @param end * @return The list with the elements */ public static <E> List<E> subList(final List<E> oriList, int start, int end) { if (start < 0 || end >= oriList.size()) { return null; } List<E> list = new ArrayList<E>(end - start + 1); for (int i = start; i <= end; i++) { list.add(oriList.get(i)); } return list; } }
parent, final Iterable