public class ListExt extends CollectionExt
| Constructor and Description |
|---|
ListExt() |
| Modifier and Type | Method and Description |
|---|---|
static <T> java.util.List<T> |
create(T... elements)
Returns a list (an ArrayList) initialized with the given elements.
|
static <T> T |
first(java.util.List<T> list)
Returns the first element in the list.
|
static <T> T |
get(java.util.List<T> list,
int index)
Returns the nth element in the list, where n can be negative, to index
from the end of the list.
|
static java.lang.Integer |
getIndex(java.lang.Integer size,
java.lang.Integer index)
Converts the index, which can be positive or negative, to one within the
given size, representing the length of a list.
|
static <Type> Type |
getRandomElement(java.util.List<Type> list)
Returns a random element from the list, or null if the list is null or empty.
|
static <T> T |
last(java.util.List<T> list)
Returns the last element in the list.
|
static <T> boolean |
removeAll(java.util.List<T> list,
T element)
Removes all occurrances of
element from list, returning whether any
were found. |
any, contains, hasAll, hasAny, intersection, intersectionpublic static <T> T first(java.util.List<T> list)
public static <T> T last(java.util.List<T> list)
public static <T> T get(java.util.List<T> list,
int index)
public static java.lang.Integer getIndex(java.lang.Integer size,
java.lang.Integer index)
public static <T> boolean removeAll(java.util.List<T> list,
T element)
element from list, returning whether any
were found. Returns false if list is null.public static <Type> Type getRandomElement(java.util.List<Type> list)
@SafeVarargs public static <T> java.util.List<T> create(T... elements)
Arrays.asList(...),
which returns a fixed-size array). The following two blocks are
equivalent:
List<String> names = new ArrayList<String>(Arrays.asList("kevin", "jacob", "isaac"));
names.add("henry");
List<String> names = list("kevin", "jacob", "isaac");
names.add("henry");