Here you can find the source of getLastXItems(int lastXItems, List
public static <T> List<T> getLastXItems(int lastXItems, List<T> list)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.Collection; import java.util.List; public class Main { public static <T> List<T> getLastXItems(int lastXItems, List<T> list) { ArrayList<T> sizedList = new ArrayList<T>(list); if (lastXItems < 0) lastXItems = 0;/*from w ww. j ava 2s. com*/ sizedList.subList(0, Math.max(sizedList.size() - lastXItems, 0)).clear(); return sizedList; } public static int size(Collection<?> col) { return col == null ? 0 : col.size(); } }