public final class Lists
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static <T> java.util.List<java.util.List<T>> |
partition(java.util.List<T> list,
int size)
Returns consecutive sublists of a list,
each of the same size (the final list may be smaller).
|
static <T> java.util.List<T> |
reverse(java.util.List<T> list)
Returns a reversed view of the specified list.
|
static <T> void |
sortByPosition(java.util.List<T> list) |
public static <T> java.util.List<T> reverse(java.util.List<T> list)
Lists.reverse(Arrays.asList(1, 2, 3))
returns a list containing 3,
2, 1
. The returned list is backed by this list, so changes in the returned
list are reflected in this list, and vice-versa. The returned list supports
all of the optional list operations supported by this list.
The returned list is random-access if the specified list is random access.
public static <T> java.util.List<java.util.List<T>> partition(java.util.List<T> list, int size)
[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.
list
- the list to return consecutive sublists ofsize
- the desired size of each sublist (the last may be
smaller)java.lang.IllegalArgumentException
- if partitionSize
is nonpositivepublic static <T> void sortByPosition(java.util.List<T> list)