Java List Split split(List list, final int parts)

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

Description

split

License

Apache License

Declaration

static <T> List<List<T>> split(List<T> list, final int parts) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    static <T> List<List<T>> split(List<T> list, final int parts) {
        List<List<T>> subLists = new ArrayList<>(parts);
        for (int i = 0; i < parts; i++) {
            subLists.add(new ArrayList<T>());
        }//from   w  ww  .  j a v  a 2s. c  om
        for (int i = 0; i < list.size(); i++) {
            subLists.get(i % parts).add(list.get(i));
        }
        return subLists;
    }
}

Related

  1. split(List data, int max)
  2. split(List list)
  3. split(List list, String separator)
  4. split(List list, String separator)
  5. split(List list)
  6. split(List list, int size)
  7. split(List list, int size)
  8. split(List list, int size)
  9. split(List list, int size)