public final class Iterables
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static <T> java.lang.Iterable<java.util.List<T>> |
partition(java.lang.Iterable<T> iterable,
int size)
Divides an iterable into unmodifiable sublists of the given size (the final
iterable may be smaller).
|
static <T> java.lang.Iterable<java.util.List<T>> |
partition(java.util.List<T> list,
int size) |
public static <T> java.lang.Iterable<java.util.List<T>> partition(java.lang.Iterable<T> iterable, int size)
[a, b, c, d, e]
with a partition size of 3 yields [[a, b, c], [d, e]]
-- an outer iterable containing two inner lists of
three and two elements, all in the original order.
Iterators returned by the returned iterable do not support the Iterator.remove()
method. The returned lists implement RandomAccess
,
whether or not the input list does.
Note: The next method of the iterator within the Iterable is atomic.
iterable
- the iterable to return a partitioned view ofsize
- the desired size of each partition (the last may be smaller)iterable
divided into partitionsjava.lang.IllegalArgumentException
- if size
is nonpositivepublic static <T> java.lang.Iterable<java.util.List<T>> partition(java.util.List<T> list, int size)