Package org.apache.hadoop.util
Class Lists
java.lang.Object
org.apache.hadoop.util.Lists
Static utility methods pertaining to
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.-
Method Summary
Modifier and TypeMethodDescriptionstatic <E> ArrayList<E>Creates a mutable, emptyArrayListinstance.static <E> ArrayList<E>newArrayList(E... elements) Creates a mutableArrayListinstance containing the given elements.static <E> ArrayList<E>newArrayList(Iterable<? extends E> elements) Creates a mutableArrayListinstance containing the given elements; a very thin shortcut for creating an empty list then calling Iterables#addAll.static <E> ArrayList<E>newArrayList(Iterator<? extends E> elements) Creates a mutableArrayListinstance containing the given elements; a very thin shortcut for creating an empty list and then calling Iterators#addAll.static <E> ArrayList<E>newArrayListWithCapacity(int initialArraySize) Creates anArrayListinstance backed by an array with the specified initial size; simply delegates toArrayList(int).static <E> ArrayList<E>newArrayListWithExpectedSize(int estimatedSize) Creates anArrayListinstance to holdestimatedSizeelements, plus an unspecified amount of padding; you almost certainly mean to callnewArrayListWithCapacity(int)(see that method for further advice on usage).static <E> LinkedList<E>Creates a mutable, emptyLinkedListinstance.static <E> LinkedList<E>newLinkedList(Iterable<? extends E> elements) Creates a mutableLinkedListinstance containing the given elements; a very thin shortcut for creating an empty list then calling Iterables#addAll.Returns consecutive sub-lists of a list, each of the same size (the final list may be smaller).
-
Method Details
-
newArrayList
Creates a mutable, emptyArrayListinstance.- Type Parameters:
E- Generics Type E.- Returns:
- ArrayList Generics Type E.
-
newArrayList
Creates a mutableArrayListinstance 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 callingCollections.addAll(java.util.Collection<? super T>, T...).- Type Parameters:
E- Generics Type E.- Parameters:
elements- elements.- Returns:
- ArrayList Generics Type E.
-
newArrayList
Creates a mutableArrayListinstance containing the given elements; a very thin shortcut for creating an empty list then calling Iterables#addAll.- Type Parameters:
E- Generics Type E.- Parameters:
elements- elements.- Returns:
- ArrayList Generics Type E.
-
newArrayList
Creates a mutableArrayListinstance containing the given elements; a very thin shortcut for creating an empty list and then calling Iterators#addAll.- Type Parameters:
E- Generics Type E.- Parameters:
elements- elements.- Returns:
- ArrayList Generics Type E.
-
newArrayListWithCapacity
Creates anArrayListinstance backed by an array with the specified initial size; simply delegates toArrayList(int).- Type Parameters:
E- Generics Type E.- Parameters:
initialArraySize- the exact size of the initial backing array for the returned array list (ArrayListdocumentation calls this value the "capacity").- Returns:
- a new, empty
ArrayListwhich is guaranteed not to resize itself unless its size reachesinitialArraySize + 1. - Throws:
IllegalArgumentException- ifinitialArraySizeis negative.
-
newArrayListWithExpectedSize
Creates anArrayListinstance to holdestimatedSizeelements, plus an unspecified amount of padding; you almost certainly mean to callnewArrayListWithCapacity(int)(see that method for further advice on usage).- Type Parameters:
E- Generics Type E.- Parameters:
estimatedSize- an estimate of the eventualList.size()of the new list.- Returns:
- a new, empty
ArrayList, sized appropriately to hold the estimated number of elements. - Throws:
IllegalArgumentException- ifestimatedSizeis negative.
-
newLinkedList
Creates a mutable, emptyLinkedListinstance.Performance note:
ArrayListandArrayDequeconsistently outperformLinkedListexcept in certain rare and specific situations. Unless you have spent a lot of time benchmarking your specific needs, use one of those instead.- Type Parameters:
E- Generics Type E.- Returns:
- Generics Type E List.
-
newLinkedList
Creates a mutableLinkedListinstance containing the given elements; a very thin shortcut for creating an empty list then calling Iterables#addAll.Performance note:
ArrayListandArrayDequeconsistently outperformLinkedListexcept in certain rare and specific situations. Unless you have spent a lot of time benchmarking your specific needs, use one of those instead.- Type Parameters:
E- Generics Type E.- Parameters:
elements- elements.- Returns:
- Generics Type E List.
-
partition
Returns consecutive sub-lists of a list, each of the same size (the final list may be smaller).- Type Parameters:
T- Generics Type.- Parameters:
originalList- original big list.pageSize- desired size of each sublist ( last one may be smaller)- Returns:
- a list of sub lists.
-