public final class CollectionUtil extends Object
Modifier and Type | Method and Description |
---|---|
static <E> List<E> |
asListWithoutNullElements(E... elements) |
static <E> Collection<E> |
nullToEmpty(Collection<E> collection) |
static <E> Iterator<E> |
nullToEmpty(Iterator<E> iterator) |
static <E> List<E> |
nullToEmpty(List<E> list) |
static <E> Set<E> |
nullToEmpty(Set<E> set) |
static <E> List<List<E>> |
splitList(List<E> inputList,
int maxSize)
Splits a given
List into multiple List s, each with the maximum size specified. |
static <E> List<Set<E>> |
splitSet(Set<E> inputSet,
int maxSize)
Splits a given
Set into multiple Set s, each with the maximum size specified. |
public static <E> List<Set<E>> splitSet(Set<E> inputSet, int maxSize)
Set
into multiple Set
s, each with the maximum size specified.
For example, imagine a Set
with 26 elements. Invoking this method with maxSize == 10
will cause a resulting List
having 3 Set
elements. The first 2 of the Set
elements each have 10 elements, while the 3rd one will have only 6 elements.
Please note that the order is maintained (LinkedHashSet
is used internally for each
segment-Set
).
inputSet
- the Set
to be split. Must not be null
. This Set
is not
modified in any way by this method.maxSize
- the maximum size of each resulting segment-Set
. Must be greater than 0.List
containing all elements from the given inputSet
in the same order,
grouped in groups each not greater than maxSize
. Never null
.splitList(List, int)
public static <E> List<List<E>> splitList(List<E> inputList, int maxSize)
List
into multiple List
s, each with the maximum size specified.
For example, imagine a List
with 26 elements. Invoking this method with maxSize == 10
will cause a resulting List
having 3 List
elements. The first 2 of the List
elements each have 10 elements, while the 3rd one will have only 6 elements.
Please note that the order is maintained.
inputList
- the List
to be split. Must not be null
. This List
is not
modified in any way by this method.maxSize
- the maximum size of each resulting segment-List
. Must be greater than 0.List
containing all elements from the given inputList
in the same order,
grouped in groups each not greater than maxSize
. Never null
.splitSet(Set, int)
public static <E> List<E> nullToEmpty(List<E> list)
public static <E> Set<E> nullToEmpty(Set<E> set)
public static <E> Collection<E> nullToEmpty(Collection<E> collection)
public static <E> Iterator<E> nullToEmpty(Iterator<E> iterator)
@SafeVarargs public static <E> List<E> asListWithoutNullElements(E... elements)
Copyright © 2013–2019. All rights reserved.