@@ -0,0 +1,2132 @@
+package com.levelup.java.collections;%0A%0Aimport static org.hamcrest.CoreMatchers.hasItems;%0Aimport static org.junit.Assert.assertThat;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0Aimport org.apache.log4j.Logger;%0Aimport org.junit.Ignore;%0Aimport org.junit.Test;%0A%0Aimport com.google.common.collect.Lists;%0A%0A/**%0A * This java example will demonstrate partitioning a list, %0A * or breaking a list into sublists based on specified size.%0A * %0A * @author Justin Musgrove%0A * @see %3Ca href='http://www.leveluplunch.com/java/examples/partition-list/'%3EPartition a list%3C/a%3E%0A * %0A */%0Apublic class PartitionList %7B%0A%09%0A%09private static final Logger logger = Logger.getLogger(PartitionList.class);%0A%0A%09List%3CString%3E playerDecisions = Lists.newArrayList(%0A%09%09%09%22Hit%22, %0A%09%09%09%22Stand%22, %0A%09%09%09%22Double down%22, %0A%09%09%09%22Split%22, %0A%09%09%09%22Surrender%22);%0A%0A%09@Test%0A%09public void partition_list_java () %7B%0A%09%09%0A%09%09List%3CList%3CString%3E%3E decisionsBy2 = new ArrayList%3CList%3CString%3E%3E();%0A%09%09%0A%09    final int sizeOfList = playerDecisions.size();%0A%09    final int breakApart = 2;%0A%09    %0A%09    for (int i = 0; i %3C sizeOfList; i += breakApart) %7B%0A%09    %09decisionsBy2.add(new ArrayList%3CString%3E (%0A%09        %09playerDecisions.subList(i, Math.min(sizeOfList, i + breakApart)))%0A%09        );%0A%09    %7D%0A%09    %0A%09%09logger.info(decisionsBy2);%0A%09%09%0A%09%09assertThat(decisionsBy2.get(0), hasItems(%22Hit%22, %22Stand%22));%0A%09%09assertThat(decisionsBy2.get(1), hasItems(%22Double down%22, %22Split%22));%0A%09%09assertThat(decisionsBy2.get(2), hasItems(%22Surrender%22));%0A%09%7D%0A%0A%09@Test%0A%09public void partition_list_guava () %7B%0A%09%09%0A%09%09List%3CList%3CString%3E%3E decisionsBy2 = Lists.partition(playerDecisions, 2);%0A%09%09%0A%09%09logger.info(decisionsBy2);%0A%0A%09    assertThat(decisionsBy2.get(0), hasItems(%22Hit%22, %22Stand%22));%0A%09    assertThat(decisionsBy2.get(1), hasItems(%22Double down%22, %22Split%22));%0A%09    assertThat(decisionsBy2.get(2), hasItems(%22Surrender%22));%0A%09%7D%0A%09%0A%09@Ignore(%22Will be released in collections 4%22)%0A%09@Test%0A%09public void partition_list_apache_commons () %7B%0A%09%09// TODO not yet released, collections 4%0A%09%09//%09ListUtils.partition(playerDecisions, 2)%0A%09%09//%09http://commons.apache.org/proper/commons-collections/apidocs/org/apache/commons/collections4/ListUtils.html#partition(java.util.List, int)%0A%09%7D%0A%7D%0A

add partition list