Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.List; public class Main { public static <T> List<T> popFirstSubList(List<T> originList, T fromObj, T toObj) { int fromIndex = originList.indexOf(fromObj); if (fromIndex == -1) { return null; } int toIndex = originList.indexOf(toObj) + 1; if (toIndex == 0) { return null; } return popSubList(originList, fromIndex, toIndex); } public static <T> List<T> popSubList(List<T> originList, int fromIndex, int toIndex) { List<T> subList = originList.subList(fromIndex, toIndex); List<T> result = new ArrayList<T>(subList); subList.clear(); return result; } public static List<?> subList(List<?> origin, int count) { if (origin == null || count <= 0) { return origin; } if (origin.size() < count) { count = origin.size(); } return origin.subList(0, count); } }