Java List Split split(List toSplit, int howOften)

Here you can find the source of split(List toSplit, int howOften)

Description

This does something with splitting things.

License

Open Source License

Declaration

public static <T> List<List<T>> split(List<T> toSplit, int howOften) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**//from  ww  w  .j av a2s .com
     * This does something with splitting things.
     * @author EXSolo
     */
    public static <T> List<List<T>> split(List<T> toSplit, int howOften) {
        List<List<T>> list = new ArrayList<List<T>>(howOften);

        for (int i = 0; i < howOften; i++) {
            list.add(new ArrayList<T>());
        }

        int i = 0;

        for (T t : toSplit) {
            list.get(i).add(t);
            i = (i + 1) % howOften;
        }
        return list;
    }
}

Related

  1. split(List list, int size)
  2. split(List list, int size)
  3. split(List list, int size)
  4. split(List list, int splitSize)
  5. split(List lst)
  6. split(List list, int divide)
  7. splitList(List files, int limit)
  8. splitList(List list, int number)
  9. splitList(List _list, int _elements)