Java List Split split(List list, int size)

Here you can find the source of split(List list, int size)

Description

split

License

Open Source License

Declaration

public static <T> List<List<T>> split(List<T> list, int size) 

Method Source Code


//package com.java2s;
import java.util.ArrayList;

import java.util.List;

public class Main {
    public static <T> List<List<T>> split(List<T> list, int size) {
        List<List<T>> lists = new ArrayList<List<T>>();
        int count = (list.size() / size) + (list.size() % size == 0 ? 0 : 1);
        for (int i = 0; i < count; i++) {
            int fromIndex = i * size, toIndex = (i + 1) * size;
            List<T> subList = list.subList(fromIndex, toIndex > list.size() ? list.size() : toIndex);
            lists.add(subList);/* w  ww .j a v a  2s  .  c o m*/
        }
        return lists;
    }
}

Related

  1. split(List list, String separator)
  2. split(List list, String separator)
  3. split(List list)
  4. split(List list, final int parts)
  5. split(List list, int size)
  6. split(List list, int size)
  7. split(List list, int size)
  8. split(List list, int splitSize)
  9. split(List lst)