public final class ArrayUtil extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T> T[] |
append(T[] list,
T item)
Inserts specified item in specified array at the end of specified
array.
|
static <T> int |
find(T[] list,
T item)
Searches specified array for specified item.
|
static <T> int |
indexOf(T[] list,
T item)
Searches specified array for specified item.
|
static <T> T[] |
insert(T[] list,
int index,
T item)
Equivalent to
insert(list,
index, new T[] { item}). |
static <T> T[] |
insert(T[] list,
int index,
T[] items)
Inserts specified items in specified array at specified index.
|
static <T> T[] |
prepend(T[] list,
T item)
Inserts specified item in specified array at the beginning of specified
array.
|
static <T> T[] |
remove(T[] list,
T item)
Remove specified item from specified array.
|
static <T> T[] |
removeAt(T[] list,
int index)
Equivalent to
remove(list, index,
1). |
static <T> T[] |
removeAt(T[] list,
int index,
int count)
Removes a range of items found at specified index from specified array.
|
static <T> void |
reverse(T[] list)
Reverses the order of the items in the specified array.
|
static <T> T[] |
subArray(T[] list,
int start)
Equivalent to
subArray(list, start, list.length). |
static <T> T[] |
subArray(T[] list,
int start,
int end)
Returns a sub-array of specified array.
|
static <T> T[] |
trimToSize(T[] list,
int listSize)
Returns specified array if its length is equal to specified size;
otherwise returns a copy of specified array having specified size.
|
public static final <T> T[] trimToSize(T[] list,
int listSize)
T - the type of the components of the arraylist - array whose size needs to be adjustedlistSize - the size of the returned arraylistSize componentspublic static final <T> T[] subArray(T[] list,
int start)
subArray(list, start, list.length).public static final <T> T[] subArray(T[] list,
int start,
int end)
T - the type of the components of the arraylist - the arraystart - the begin index, inclusiveend - the end index, exclusiveIndexOutOfBoundsException - if start or end
are negative, if end is greater than list.length
or if start is greater than endpublic static final <T> T[] insert(T[] list,
int index,
T item)
insert(list,
index, new T[] { item}).public static final <T> T[] insert(T[] list,
int index,
T[] items)
T - the type of the components of the arraylist - list to be modifiedindex - items are inserted at this position.
Note that index may be equal to the size of the array. This means: insert at end.
items - items to be inserteditems.length
componentspublic static final <T> T[] prepend(T[] list,
T item)
T - the type of the components of the arraylist - list to be modifieditem - item to be insertedpublic static final <T> T[] append(T[] list,
T item)
T - the type of the components of the arraylist - list to be modifieditem - item to be insertedpublic static final <T> T[] remove(T[] list,
T item)
equals() and not == (using indexOf(T[], T)).T - the type of the components of the arraylist - list to be modifieditem - item to be removedpublic static final <T> int indexOf(T[] list,
T item)
find(T[], T),
items are compared using equals() and not ==.T - the type of the components of the arraylist - a list possibly containing itemitem - searched itempublic static final <T> int find(T[] list,
T item)
indexOf(T[], T),
items are compared using == and not equals().T - the type of the components of the arraylist - a list possibly containing itemitem - searched itempublic static final <T> T[] removeAt(T[] list,
int index)
remove(list, index,
1).public static final <T> T[] removeAt(T[] list,
int index,
int count)
T - the type of the components of the arraylist - list to be modifiedindex - items are removed at this positioncount - number of items to be removedpublic static final <T> void reverse(T[] list)