/* package whatever; // don't place package name! */

import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream;
import java.util.stream.Collectors;

class Ideone {
	public static void main (String[] args) {
		try {
			partition(List.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), 2);
			System.out.println("Should have thrown, but did not");
		} catch (IllegalArgumentException e) {
			System.out.println("Threw exception as expepcted");
		}
		System.out.println(partition(
			List.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12),
			2));
		System.out.println(partition(
			List.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12),
			3));
		System.out.println(partition(
			List.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12),
			4));
	}
	
	public static List<List<Integer>> partition(
			List<Integer> list, 
			int partitionSize) {
        int listSize = list.size();
        if (listSize % partitionSize != 0) {
			throw new IllegalArgumentException("The size of the list must be "
					+ "divisible without remainder by the partition size.");
		}
        final int parts = listSize / partitionSize;
		return IntStream.range(0, parts)
            .mapToObj(i -> list.subList(2 * i, 2 * i + partitionSize))
            .collect(Collectors.toList());
	}
}