Java List Partition partitionList(final List originalList, final int chunkSize)

Here you can find the source of partitionList(final List originalList, final int chunkSize)

Description

partition List

License

Apache License

Declaration

private static <T> List<List<T>> partitionList(final List<T> originalList, final int chunkSize) 

Method Source Code

//package com.java2s;
// Licensed to the Apache Software Foundation (ASF) under one

import java.util.ArrayList;

import java.util.List;

public class Main {
    private static <T> List<List<T>> partitionList(final List<T> originalList, final int chunkSize) {
        final List<List<T>> listOfChunks = new ArrayList<List<T>>();
        for (int i = 0; i < originalList.size() / chunkSize; i++) {
            listOfChunks.add(originalList.subList(i * chunkSize, i * chunkSize + chunkSize));
        }// www . j a  v  a2 s.  co  m
        if (originalList.size() % chunkSize != 0) {
            listOfChunks.add(originalList.subList(originalList.size() - originalList.size() % chunkSize,
                    originalList.size()));
        }
        return listOfChunks;
    }
}

Related

  1. partition(List list, int size)
  2. partition(List longList, int length)
  3. partition(List orig, int size)
  4. partition(List sourceList, int numberOfSegments)
  5. partitionIntoFolds( List values, int numFolds)
  6. partitionList(List list, int folds)
  7. partitionList(List list, final int partitionSize)
  8. partitionVariable(List arr, int chunk)
  9. removePartition(List donorPartitionList, int partition)