public class ListUtils extends Object
| Constructor and Description |
|---|
ListUtils() |
| Modifier and Type | Method and Description |
|---|---|
static <T> List<List<T>> |
partition(List<T> list,
int size)
Returns consecutive
sublists of a
list, each of the same size (the final list may be smaller). |
public static <T> List<List<T>> partition(List<T> list, int size)
sublists of a
list, each of the same size (the final list may be smaller). For example,
partitioning a list containing [a, b, c, d, e] with a partition
size of 3 yields [[a, b, c], [d, e]] -- an outer list containing
two inner lists of three and two elements, all in the original order.
The outer list is unmodifiable, but reflects the latest state of the
source list. The inner lists are sublist views of the original list,
produced on demand using List.subList(int, int), and are subject
to all the usual caveats about modification as explained in that API.
Adapted from http://code.google.com/p/guava-libraries/
T - the element typelist - the list to return consecutive sublists ofsize - the desired size of each sublist (the last may be smaller)NullPointerException - if list is nullIllegalArgumentException - if size is not strictly positiveCopyright © 2001–2021 JBoss by Red Hat. All rights reserved.