### Question:
ListUtils { public static <T> List<List<T>> partition(List<T> list, int size) { if (size <= 0) { throw new IllegalArgumentException(size + " <= 0"); } if (list == null || list.size() == 0) { return new ArrayList<>(0); } List<List<T>> result = new ArrayList<>(list.size() / size + 1); for (int fromIndex = 0; fromIndex < list.size(); ) { List<T> subList = getSubList(list, fromIndex, size); result.add(subList); fromIndex += size; } return result; } private  ListUtils(); static boolean isEmpty(List<T> list); static boolean isNotEmpty(List<T> list); static List<List<T>> partition(List<T> list, int size); static List<T> getSubList(List<T> list, int fromIndex, int limit);  }### Answer:
@Test public void testPartition() { List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9); List<List<Integer>> partition = ListUtils.partition(list, 2); Assert.assertEquals(5, partition.size()); Assert.assertEquals(2, partition.get(0).size()); Assert.assertEquals(2, partition.get(1).size()); Assert.assertEquals(2, partition.get(2).size()); Assert.assertEquals(2, partition.get(3).size()); Assert.assertEquals(1, partition.get(4).size()); List<Integer> list2 = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8); List<List<Integer>> partition2 = ListUtils.partition(list2, 2); Assert.assertEquals(4, partition2.size()); Assert.assertEquals(2, partition2.get(0).size()); Assert.assertEquals(2, partition2.get(1).size()); Assert.assertEquals(2, partition2.get(2).size()); Assert.assertEquals(2, partition2.get(3).size()); List<Integer> list3 = new ArrayList<>(0); List<List<Integer>> partition3 = ListUtils.partition(list3, 12); Assert.assertEquals(0, partition3.size()); List<List<Integer>> partition4 = ListUtils.partition(null, 12); Assert.assertEquals(0, partition4.size()); }