public final class ArrayUtils extends Object
Constructor and Description |
---|
ArrayUtils() |
Modifier and Type | Method and Description |
---|---|
static <T> T[] |
append(T[] array,
Collection<T> newElements)
Appends one or more elements to an array.
|
static <T> T[] |
append(T[] array,
T... newElements)
Appends one or more elements to an array.
|
static <T> Set<T> |
asSet(T[] array)
Converts the specified array to a
Set . |
static <T> T[] |
combine(T[]... arrays)
Combine an arbitrary number of arrays into a single array.
|
static boolean |
contains(String element,
String[] array)
Returns
String.equals(Object)
method. |
static <T> boolean |
contains(T element,
T[] array)
Returns
Object.equals(Object)
method. |
static List |
copyToList(Object array,
List list)
Copies the specified array into the specified list.
|
static boolean |
equals(String[] a1,
String[] a2)
Returns
|
static Object |
getFirst(Object val)
Returns the first object in the specified collection or array.
|
static int |
indexOf(String element,
String[] array)
Returns the index position of the element in the specified array using the
String.equals(Object) method. |
static <T> int |
indexOf(T element,
T[] array)
Returns the index position of the element in the specified array using the
Object.equals(Object) method. |
static boolean |
isArray(Object array)
Returns
|
static Iterator<Object> |
iterator(Object array)
Returns an iterator against an array.
|
static <T> T[] |
reverse(T[] array)
Creates a new array with reversed entries.
|
static <T> T[] |
reverseInline(T[] array)
Sorts the elements in an array without creating a new array.
|
static <T> Object |
toArray(Collection<?> c,
Class<T> componentType)
Converts the specified collection to an array.
|
static List<?> |
toList(Iterable<?> i)
Converts an Iterable to a list.
|
static <T> List<T> |
toList(Object array,
Class<T> componentType)
Converts the specified array to an
ArrayList |
static <T> T[] |
toObjectArray(Collection<?> c,
Class<T> componentType)
Shortcut for calling
myList.toArray(new T[myList.size()]); |
static Object |
toPrimitiveArray(Object o)
Converts a primitive wrapper array (e.g.
|
static <T> T[] |
toReverseArray(Class<T> c,
Collection<T> l)
Converts a collection to an array containing the elements in reversed order.
|
static String[] |
toStringArray(Collection<?> c)
Converts the specified collection to an array of strings.
|
public ArrayUtils()
public static <T> T[] append(T[] array, T... newElements)
T
- The element type.array
- The array to append to.newElements
- The new elements to append to the array.public static <T> T[] append(T[] array, Collection<T> newElements)
T
- The element type.array
- The array to append to.newElements
- The new elements to append to the array.public static <T> T[] combine(T[]... arrays)
arrays
- Collection of arrays to combine.public static <T> T[] reverse(T[] array)
T
- The class type of the array.array
- The array to reverse.public static <T> T[] reverseInline(T[] array)
array
- The array to sort.public static <T> Set<T> asSet(T[] array)
Set
.
The order of the entries in the set are the same as the array.
T
- The entry type of the array.array
- The array being wrapped in a Set
interface.public static Iterator<Object> iterator(Object array)
This works with any array type (e.g. String[]
, Object[]
,
, etc...).
array
- The array to create an iterator over.public static <T> Object toArray(Collection<?> c, Class<T> componentType)
Works on both object and primitive arrays.
c
- The collection to convert to an array.componentType
- The component type of the collection.public static boolean isArray(Object array)
array
- The array to test.public static <T> List<T> toList(Object array, Class<T> componentType)
ArrayList
array
- The array to convert.componentType
- The type of objects in the array.
It must match the actual component type in the array.ArrayList
public static <T> T[] toObjectArray(Collection<?> c, Class<T> componentType)
myList.toArray(new T[myList.size()]);
c
- The collection being converted to an array.componentType
- The component type of the array.public static List copyToList(Object array, List list)
Works on both object and primitive arrays.
array
- The array to copy into a list.list
- The list to copy the values into.public static <T> boolean contains(T element, T[] array)
Object.equals(Object)
method.element
- The element to check for.array
- The array to check.public static <T> int indexOf(T element, T[] array)
Object.equals(Object)
method.element
- The element to check for.array
- The array to check.-1
if the array doesn't contain the
element, or the array or element is public static boolean contains(String element, String[] array)
String.equals(Object)
method.element
- The element to check for.array
- The array to check.public static int indexOf(String element, String[] array)
String.equals(Object)
method.element
- The element to check for.array
- The array to check.-1
if the array doesn't contain the element, or the array or element is public static Object toPrimitiveArray(Object o)
Integer[]
) to a primitive array (e.g. int []
).o
- The array to convert. Must be a primitive wrapper array.IllegalArgumentException
- If object is not a wrapper object array.public static List<?> toList(Iterable<?> i)
i
- The iterable to convert.public static Object getFirst(Object val)
val
- The collection or array object.public static String[] toStringArray(Collection<?> c)
Entries are converted to strings using Object.toString()
.
c
- The collection to convert.public static boolean equals(String[] a1, String[] a2)
a1
- Array #1.a2
- Array #2.public static <T> T[] toReverseArray(Class<T> c, Collection<T> l)
c
- The component type of the array.l
- The collection to convert.
Copyright © 2018 Apache. All rights reserved.