Correctly intercept the content of the specified position of the List

Correctly intercept the content of the specified position of the List

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

public class ListUtils {
    public static <T> List<T> getSubList(List<T> 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;
    }

}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324741986&siteId=291194637