List<Integer> 分页

 
  public static void main(String [] args){
        try {
            List<Integer> skuIdList=new ArrayList<>();
            skuIdList.add(1);
            skuIdList.add(2);
            skuIdList.add(3);
            skuIdList.add(4);
            skuIdList.add(5);

            List<List<Integer>> choppedList = chopped(skuIdList, 2);

            for(List<Integer> skuList_page:choppedList){
                int c=3;
            }
            int a=2;

        }catch (Exception ex){
            int d=3;
        }
    }

    public static <T> List<List<T>> chopped(List<T> list, final int L) {
        List<List<T>> parts = new ArrayList<List<T>>();
        final int N = list.size();
        for (int i = 0; i < N; i += L) {
            parts.add(new ArrayList<T>(list.subList(i, Math.min(N, i + L))));
        }
        return parts;
    }
 
 

猜你喜欢

转载自www.cnblogs.com/caohuimingfa/p/9328142.html