public class Array<T> extends java.util.ArrayList<T> implements Sequence<T>
| Modifier and Type | Field and Description |
|---|---|
static long |
serialVersionUID |
| Constructor and Description |
|---|
Array()
Creates an empty list.
|
Array(java.util.Collection<? extends T> coll)
Creates a list from the collection, copying its elements.
|
Array(T... ary)
Creates the list from a varargs array.
|
| Modifier and Type | Method and Description |
|---|---|
Array<T> |
append(T obj)
Adds the element to the list, similar to
java.util.ArrayList#add, and returns
the list, so this method can be chained: |
Array<T> |
compact()
Returns a new list that contains only the non-null elements from this list, in the same
order as in this list.
|
boolean |
containsAny(java.util.Collection<T> coll)
Returns whether this list contains any element in the given collection.
|
boolean |
containsAny(T... args)
Returns whether this list contains any element in the given array.
|
Array<T> |
elements(int... indices)
Returns a list of the elements at the given indices.
|
static <T> Array<T> |
empty()
Creates an empty list from the given array.
|
T |
first()
Returns the first element in the list, or null if the list is empty.
|
T |
get(int index)
Returns the
nth element in the list. |
Array<T> |
get(int fromIndex,
int toIndex)
Returns a Array containing the
mth element through the nth element
in the list, both inclusive. |
T |
getRandomElement()
Returns a random element from the list, or null if the list is empty.
|
Array<T> |
intersection(Array<T> other)
Returns a list of elements in both this array and the other.
|
java.lang.String |
join(java.lang.String delimiter)
Returns the list as a String, joined by the delimiter.
|
T |
last()
Returns the last element in the list, or null if the list is empty.
|
Array<T> |
minus(Array<T> other)
Returns a new list, containing the elements of this list that are not in the other.
|
static <T> Array<T> |
of(T... ary)
Creates a list from the given array.
|
Array<T> |
plus(Array<T> other)
Returns a new list, concatenating the other list with this one.
|
boolean |
removeAll(T element)
Removes all occurrances of
element from list, returning whether any
were found. |
T |
set(int index,
T value)
Sets the
nth element in the list. |
Array<T> |
sorted()
Returns a copy of this array, sorted.
|
T |
takeFirst()
Removes and returns the first element in the list.
|
T |
takeLast()
Removes and returns the last element in the list.
|
java.util.ArrayList<java.lang.String> |
toStringArrayList()
Returns the list as a list of strings, with each element converted via
toString(). |
StringList |
toStringList()
Returns the list as a StringList, with each element converted via
toString(). |
Array<T> |
unique()
Returns a new list that contains unique elements from the list, in the same order as in this
list.
|
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, forEach, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, size, sort, spliterator, subList, toArray, toArray, trimToSizefinalize, getClass, notify, notifyAll, wait, wait, waitpublic static final long serialVersionUID
public Array()
public Array(java.util.Collection<? extends T> coll)
coll can be null.@SafeVarargs public Array(T... ary)
@SafeVarargs public static <T> Array<T> of(T... ary)
Array<Integer> list = Array.<Integer>of(); Array<Integer> list = Array.of(6); Array<Integer> list = Array.of(6, 7); Array<Integer> list = Array.of(6, 7, 8);
public static <T> Array<T> empty()
Array.<Type>empty()
is used to denote the generic type.
Array<String> list = Array.<String>empty();
public StringList toStringList()
toString().toStringArrayList(),
StringListpublic java.util.ArrayList<java.lang.String> toStringArrayList()
toString().toStringList()public boolean containsAny(java.util.Collection<T> coll)
@SafeVarargs public final boolean containsAny(T... args)
public T first()
public T last()
public T get(int index)
nth element in the list.
Unlike java.util.ArrayList#get, org.incavaijdk.collect.Array#get
supports negative indices, as do languages such as Perl and Ruby.
If n is negative, then the index is the offset from the end, where
-1 is the last element, -2 is the second to last element, and so on
and so forth. If n is out of range (not within 0 ... size()), then
null is returned.
public Array<T> get(int fromIndex, int toIndex)
mth element through the nth element
in the list, both inclusive.
If m n is negative, then the index is the offset from the end,
where -1 is the last element, -2 is the second to last element, and
so on and so forth. If m or n is out of range (not within 0
... size()), then an empty set is returned.
public Array<T> append(T obj)
java.util.ArrayList#add, and returns
the list, so this method can be chained:
Array<Integer> nums = Array.of(1, 2, 3);
nums.append(4).append(5);
public T set(int index, T value)
nth element in the list.
If n is negative, then the index is the offset from the end, where
-1 is the last element, -2 is the second to last element. Unlike
ArrayList#set, this method honors the dynamically sized aspect of the list, and
resizes it accordingly when set(index, obj) && index > size().
However, set(-index, obj) (a negative index value) will result in an
IllegalArgumentException when -index > -size().
public boolean removeAll(T element)
element from list, returning whether any
were found.element - the element to removepublic T getRandomElement()
public T takeFirst()
public T takeLast()
public Array<T> unique()
public Array<T> compact()
public java.lang.String join(java.lang.String delimiter)
public Array<T> plus(Array<T> other)
public Array<T> minus(Array<T> other)
public Array<T> elements(int... indices)
get, negative
indices are treated as offsets from the last element.
Array<Integer> list = Array.of(6, 7, 8);
Array<Integer> l2 = list.elements(0); // [ 6 ]
Array<Integer> l3 = list.elements(0, 1); // [ 6, 7 ]
Array<Integer> l4 = list.elements(1, 0); // [ 7, 6 ]
Array<Integer> l5 = list.elements(-1, -2, 1); // [ 8, 7, 7 ]
get(int)public Array<T> intersection(Array<T> other)