This example will demonstrate how to partition an ArrayList using java, java 8, guava and apache commons. The setup data is a List of strings that will be broken up into consecutive sublists of the condition specified.
Straight up Java
This snippet will use a for loop to break apart a list of strings into a sublist.
Using java 8, the snippet will show how to use a partitioning function. The partitioning function will return Map < Boolean,List < String >> where the key is a boolean and the results are based on the behavior of the predicate. Created by a lambda expression, the predicate shown will return true if the string starts with 's'. The resulting map will have a collection of strings that start with 's' where the key equals true and false where a list of strings do not start with 's'. So at most you will have two keys or two different groups. This return collection type is similiar to guava multimap.
This snippet will show how to split an ArrayList into smaller arraylists using guava. Guava's Lists collection utiltiy partition method will return a sublist of a list, with each sublist the same size and the last varying in size depending on the number of elements.
This snippet will show how to divide a list into multiple lists with apache commons.