正确截取List指定位置的内容

正确截取List指定位置的内容

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

public class ListUtils {
    public static  List getSubList(List list, int fromIndex, int toIndex) {
        //list.stream().limit(toIndex);
        if (toIndex > list.size()) {
        }
        List listClone = list;
        List sub = listClone.subList(fromIndex, toIndex);
        List two = new ArrayList(sub);
        sub.clear(); // since sub is backed by one, this removes all sub-list items from one
        return two;
    }

}

转载于:https://www.cnblogs.com/androidsuperman/p/8926232.html

你可能感兴趣的:(正确截取List指定位置的内容)