public static <T> List<List<T>> partition(List<T> originalList, int pageSize) {

    Preconditions.checkArgument(originalList != null && originalList.size() > 0,
            "Invalid original list");
    Preconditions.checkArgument(pageSize > 0, "Page size should " +
            "be greater than 0 for performing partition");

    List<List<T>> result = new ArrayList<>();
    int i=0;
    while (i < originalList.size()) {
      result.add(originalList.subList(i,
              Math.min(i + pageSize, originalList.size())));
      i = i + pageSize;
    }
    return result;
  }
@Test
  public void testListsPartition() {
    List<String> list = new ArrayList<>();
    list.add("a");
    list.add("b");
    list.add("c");
    list.add("d");
    list.add("e");
    List<List<String>> res = Lists.
            partition(list, 2);
    Assertions.assertThat(res)
            .describedAs("Number of partitions post partition")
            .hasSize(3);
    Assertions.assertThat(res.get(0))
            .describedAs("Number of elements in first partition")
            .hasSize(2);
    Assertions.assertThat(res.get(2))
            .describedAs("Number of elements in last partition")
            .hasSize(1);

    List<List<String>> res2 = Lists.
            partition(list, 1);
    Assertions.assertThat(res2)
            .describedAs("Number of partitions post partition")
            .hasSize(5);
    Assertions.assertThat(res2.get(0))
            .describedAs("Number of elements in first partition")
            .hasSize(1);
    Assertions.assertThat(res2.get(4))
            .describedAs("Number of elements in last partition")
            .hasSize(1);

    List<List<String>> res3 = Lists.
            partition(list, 6);
    Assertions.assertThat(res3)
            .describedAs("Number of partitions post partition")
            .hasSize(1);
    Assertions.assertThat(res3.get(0))
            .describedAs("Number of elements in first partition")
            .hasSize(5);
  }