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

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) {
		final 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 List<List<Integer>> partition = new ArrayList<>();
		for (int start = 0; start < listSize; start += partitionSize) {
			partition.add(list.subList(start, start + partitionSize));
		}
		return partition;
	}
}