@Private
public final class Lists
extends java.lang.Object
List instances.
This class is Hadoop's internal use alternative to Guava's Lists
utility class.
Javadocs for majority of APIs in this class are taken from Guava's Lists
class from Guava release version 27.0-jre.| Modifier and Type | Method | Description |
|---|---|---|
static <E> java.util.ArrayList<E> |
newArrayList() |
Creates a mutable, empty
ArrayList instance. |
static <E> java.util.ArrayList<E> |
newArrayList(E... elements) |
Creates a mutable
ArrayList instance containing the given
elements. |
static <E> java.util.ArrayList<E> |
newArrayList(java.lang.Iterable<? extends E> elements) |
Creates a mutable
ArrayList instance containing the
given elements; a very thin shortcut for creating an empty list then
calling Iterables#addAll. |
static <E> java.util.ArrayList<E> |
newArrayList(java.util.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. |
static <E> java.util.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> java.util.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). |
static <E> java.util.LinkedList<E> |
newLinkedList() |
Creates a mutable, empty
LinkedList instance. |
static <E> java.util.LinkedList<E> |
newLinkedList(java.lang.Iterable<? extends E> elements) |
Creates a mutable
LinkedList instance containing the given
elements; a very thin shortcut for creating an empty list then calling
Iterables#addAll. |
static <T> java.util.List<java.util.List<T>> |
partition(java.util.List<T> originalList,
int pageSize) |
Returns consecutive sub-lists of a list, each of the same size
(the final list may be smaller).
|
public static <E> java.util.ArrayList<E> newArrayList()
ArrayList instance.E - Generics Type E.@SafeVarargs public static <E> java.util.ArrayList<E> newArrayList(E... elements)
ArrayList instance containing the given
elements.
Note that even when you do need the ability to add or remove,
this method provides only a tiny bit of syntactic sugar for
newArrayList(
asList
(...)), or for creating an empty list then calling
Collections.addAll(java.util.Collection<? super T>, T...).
E - Generics Type E.elements - elements.public static <E> java.util.ArrayList<E> newArrayList(java.lang.Iterable<? extends E> elements)
ArrayList instance containing the
given elements; a very thin shortcut for creating an empty list then
calling Iterables#addAll.E - Generics Type E.elements - elements.public static <E> java.util.ArrayList<E> newArrayList(java.util.Iterator<? extends E> elements)
ArrayList instance containing the
given elements; a very thin shortcut for creating an empty list
and then calling Iterators#addAll.E - Generics Type E.elements - elements.public static <E> java.util.ArrayList<E> newArrayListWithCapacity(int initialArraySize)
ArrayList instance backed by an array with the
specified initial size;
simply delegates to ArrayList(int).E - Generics Type E.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 + 1.java.lang.IllegalArgumentException - if initialArraySize is negative.public static <E> java.util.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).E - Generics Type E.estimatedSize - an estimate of the eventual List.size()
of the new list.ArrayList, sized appropriately to hold the
estimated number of elements.java.lang.IllegalArgumentException - if estimatedSize is negative.public static <E> java.util.LinkedList<E> newLinkedList()
LinkedList instance.
Performance note: ArrayList and
ArrayDeque consistently
outperform LinkedList except in certain rare and specific
situations. Unless you have
spent a lot of time benchmarking your specific needs, use one of those
instead.
E - Generics Type E.public static <E> java.util.LinkedList<E> newLinkedList(java.lang.Iterable<? extends E> elements)
LinkedList instance containing the given
elements; a very thin shortcut for creating an empty list then calling
Iterables#addAll.
Performance note: ArrayList and
ArrayDeque consistently
outperform LinkedList except in certain rare and specific
situations. Unless you have spent a lot of time benchmarking your
specific needs, use one of those instead.
E - Generics Type E.elements - elements.public static <T> java.util.List<java.util.List<T>> partition(java.util.List<T> originalList,
int pageSize)
T - Generics Type.originalList - original big list.pageSize - desired size of each sublist ( last one
may be smaller)Copyright © 2008–2025 Apache Software Foundation. All rights reserved.