public class ListUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
checkNotNull(T reference)
Ensures that an object reference passed as a parameter to the calling method is not null.
|
static <E> ArrayList<E> |
newArrayList()
Creates a mutable, empty
ArrayList instance (for Java 6 and earlier). |
static <E> ArrayList<E> |
newArrayList(E... elements)
Creates a mutable
ArrayList instance containing the given elements. |
static <E> ArrayList<E> |
newArrayList(Iterable<? extends E> elements)
Creates a mutable
ArrayList instance containing the given elements; |
static <E> ArrayList<E> |
newArrayList(Iterator<? extends E> elements)
Creates a mutable
ArrayList instance containing the given elements; a very thin
shortcut for creating an empty list and then calling Iterators.addAll(java.util.Collection<T>, java.util.Iterator<? extends T>). |
static <E> ArrayList<E> |
newArrayListWithCapacity(int initialArraySize)
Creates an
ArrayList instance backed by an array with the specified initial size;
simply delegates to ArrayList(int). |
static <E> ArrayList<E> |
newArrayListWithExpectedSize(int estimatedSize)
Creates an
ArrayList instance to hold estimatedSize elements, plus an
unspecified amount of padding; you almost certainly mean to call newArrayListWithCapacity(int) (see that method for further advice on usage). |
public static <E> ArrayList<E> newArrayList()
ArrayList instance (for Java 6 and earlier).
Note for Java 7 and later: this method is now unnecessary and should be treated as
deprecated. Instead, use the ArrayList constructor
directly, taking advantage of the new "diamond" syntax.
public static <E> ArrayList<E> newArrayList(E... elements)
ArrayList instance containing the given elements.public static <E> ArrayList<E> newArrayList(Iterator<? extends E> elements)
ArrayList instance containing the given elements; a very thin
shortcut for creating an empty list and then calling Iterators.addAll(java.util.Collection<T>, java.util.Iterator<? extends T>).public static <E> ArrayList<E> newArrayList(Iterable<? extends E> elements)
ArrayList instance containing the given elements;
Note for Java 7 and later: if elements is a Collection, you don't
need this method. Use the ArrayList constructor directly, taking advantage of the new "diamond"
syntax.
public static <E> ArrayList<E> newArrayListWithCapacity(int initialArraySize)
ArrayList instance backed by an array with the specified initial size;
simply delegates to ArrayList(int).
Note for Java 7 and later: this method is now unnecessary and should be treated as
deprecated. Instead, use new ArrayList<>(int)
directly, taking advantage of the new "diamond" syntax.
(Unlike here, there is no risk of overload ambiguity, since the ArrayList constructors
very wisely did not accept varargs.)
initialArraySize - the exact size of the initial backing array for the returned array list
(ArrayList documentation calls this value the "capacity")ArrayList which is guaranteed not to resize itself unless its size
reaches initialArraySize + 1IllegalArgumentException - if initialArraySize is negativepublic static <E> ArrayList<E> newArrayListWithExpectedSize(int estimatedSize)
ArrayList instance to hold estimatedSize elements, plus an
unspecified amount of padding; you almost certainly mean to call newArrayListWithCapacity(int) (see that method for further advice on usage).
Note: This method will soon be deprecated. Even in the rare case that you do want some amount of padding, it's best if you choose your desired amount explicitly.
estimatedSize - an estimate of the eventual List.size() of the new listArrayList, sized appropriately to hold the estimated number of
elementsIllegalArgumentException - if estimatedSize is negativepublic static <T> T checkNotNull(T reference)
reference - an object referenceNullPointerException - if reference is nullCopyright © 2018–2022 Alibaba Group. All rights reserved.