Here you can find the source of subList(final List
public static <T> java.util.List<T> subList(final List<T> list, final int startIndex, final int endIndex)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; public class Main { public static <T> java.util.List<T> subList(final List<T> list, final int startIndex, final int endIndex) { if (null == list || list.isEmpty()) { return new ArrayList<T>(); }//w ww . j a va 2s . c om int size = list.size(); int min = startIndex; int max = endIndex == -1 ? size : size < endIndex ? size : endIndex; if (max < min) { min = min ^ max; max = min ^ max; min = min ^ max; } if (min >= size || min < 0) { return new ArrayList<T>(); } return list.subList(min, max); } }
parent, final Iterable