| Modifier and Type | Method and Description |
|---|---|
static <T> List<T> |
append(List<T>... lists)
Makes a new, single list made of the elements of all the given lists
concatenated together.
|
static <T> List<T> |
fromArray(T[] array)
Deprecated.
Use
list(Object...) instead. |
static List<String> |
fromCSV(String csv)
Creates a list containing the elements of a comma separated string, with
the caveat that the processing is done by
StringTokenizer with the
delimiter ",". |
static <T> List<T> |
fromIterable(Iterable<T> iterable)
Creates a list containing the elements of the given iterable.
|
static <T> List<T> |
fromIterator(Iterator<T> iterator)
Creates a list containing the elements of the given iterator.
|
static <T> List<T> |
immutableListOfType(List<?> list,
Class<T> type)
Checks that all elements of the list are of the specified type, and returns
an unmodifiable copy of the list, with null elements disallowed.
|
protected static <T> List<T> |
immutableListOfType(List<?> list,
Class<T> type,
boolean nullOk)
Checks that all elements of the list are of the specified type, and returns
an unmodifiable copy of the list, with null elements either allowed or
disallowed.
|
static <T> List<T> |
immutableListOfTypeOrNull(List<?> list,
Class<T> type)
Checks that all elements of the list are of the specified type, and returns
an unmodifiable copy of the list, with null elements allowed.
|
static <T> List<T> |
list(T... elements)
Creates a modifiable list from any number of arguments.
|
static <T> ArrayList<T> |
minimalArrayList(List<T> lst)
|
static <T> LinkedList<T> |
prependAll(List<T> ofList,
LinkedList<T> toList)
Prepends the elements of
ofList to the linked list
toList, creating a new linked list from ofList if
toList is null. |
static <T> List<T> |
reverseCopy(List<T> list)
Returns a copy of the list, with elements in reverse order.
|
public static <T> List<T> list(T... elements)
Creates a modifiable list from any number of arguments.
Arrays.asList(Object...) differs from this in that it returns a
fixed-size list backed by the varargs array.
T - The type of element contained in the list.elements - A succession of elements (possibly zero).List of those elements (an empty list if no
elements).CollectionUtil2.collection(Supplier, Object...)public static <T> List<T> append(List<T>... lists)
Makes a new, single list made of the elements of all the given lists concatenated together. If a given list is null, it is ignored. If no input lists are given (taking null lists into account), the result is an empty list.
T - The type of element contained in the list.lists - A succession of lists (possibly zero).List made of the elements of all the non-null
lists concatenated together.@Deprecated public static <T> List<T> fromArray(T[] array)
list(Object...) instead.
Now that list(Object...) is generic, this method does exactly the
same thing and simply calls it.
T - The type of element contained in the list.array - An array of objects.List made of the objects in the array.list(Object...)public static <T> LinkedList<T> prependAll(List<T> ofList, LinkedList<T> toList)
Prepends the elements of ofList to the linked list
toList, creating a new linked list from ofList if
toList is null.
If toList is null, the result is a new linked list made from
ofList. If ofList is null,
T - The type of element contained in the list.ofList - The list whose elements are prepended.toList - The list to which elements are prepended.LinkedList.addFirst(Object)public static <T> ArrayList<T> minimalArrayList(List<T> lst)
T - The type of element contained in the list.lst - A list.ArrayList instance of the same elements, trimmed to the
size of the given list. If the input list is itself an
ArrayList instance, that instance is trimmed an returned
without allocating a new instance.ArrayList.ArrayList(Collection),
ArrayList.trimToSize()public static <T> List<T> fromIterator(Iterator<T> iterator)
Creates a list containing the elements of the given iterator.
The preferred way of doing this is with
IteratorUtils.toList(Iterator), which behaves exactly the same way
as this method.
T - The type of element contained in the list.iterator - An iterator.CollectionUtil2.fromIterator(Supplier, Iterator)public static <T> List<T> fromIterable(Iterable<T> iterable)
Creates a list containing the elements of the given iterable.
T - The type of element contained in the list.iterable - An iterable.CollectionUtil2.fromIterable(Supplier, Iterable)public static List<String> fromCSV(String csv)
Creates a list containing the elements of a comma separated string, with
the caveat that the processing is done by StringTokenizer with the
delimiter ",".
StringTokenizer simplistically looks for separators without a
quoting mechanism to return tokens containing the delimiter, nor does it
trim whitespace between tokens and delimiters. It also does not return
empty tokens, so calling this method with ",,," will return an
empty list, not a list of four empty strings.
csv - A simplistic CSV string.CollectionUtil2.fromCsvStringTokenizer(Supplier, String)public static <T> List<T> immutableListOfType(List<?> list, Class<T> type)
Checks that all elements of the list are of the specified type, and returns an unmodifiable copy of the list, with null elements disallowed.
T - The type of element contained in the list.list - The input list.type - The class with which all items of the list must be
assignment-compatible.NullPointerException - if the list is null or if any element is null.ClassCastException - if an item is not of the proper type.immutableListOfType(List, Class, boolean)public static <T> List<T> immutableListOfTypeOrNull(List<?> list, Class<T> type)
Checks that all elements of the list are of the specified type, and returns an unmodifiable copy of the list, with null elements allowed.
T - The type of element contained in the list.list - The input list.type - The class with which all items of the list must be
assignment-compatible.NullPointerException - if the list is nullClassCastException - if an item is not of the proper type.immutableListOfType(List, Class, boolean)protected static <T> List<T> immutableListOfType(List<?> list, Class<T> type, boolean nullOk)
Checks that all elements of the list are of the specified type, and returns an unmodifiable copy of the list, with null elements either allowed or disallowed.
T - The type of element contained in the list.list - The input list.type - The class with which all items of the list must be
assignment-compatible.nullOk - Whether null elements are allowed.NullPointerException - if the list is null or if any element is null.ClassCastException - if an item is not of the proper type.public static <T> List<T> reverseCopy(List<T> list)
Returns a copy of the list, with elements in reverse order.
T - The type of element contained in the list.list - The list to reverse.Collections.reverse(List)Copyright © 2000–2018 LOCKSS Program. All rights reserved.