Package org.apache.juneau.internal
Class ArrayUtils
java.lang.Object
org.apache.juneau.internal.ArrayUtils
Quick and dirty utilities for working with arrays.
See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <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 aSet .static <E> E[]
combine
(E[]... arrays) Combine an arbitrary number of arrays into a single array.static boolean
Returnstrue if the specified array contains the specified element using theString.equals(Object)
method.static <T> T[]
copyOf
(T[] array) Makes a copy of the specified array.static List
copyToList
(Object array, List list) Copies the specified array into the specified list.static boolean
Returnstrue if the following sorted arrays are equals.static int
Returns the index position of the element in the specified array using theString.equals(Object)
method.static boolean
Returnstrue if the specified object is an array.static final boolean
isEmptyArray
(Object[] array) Returnstrue if the specified array is null or has a length of zero.static final boolean
isEmptyArray
(Object[] array1, Object[] array2) Returnstrue if both specified arrays are null or have a length of zero.static final boolean
isNotEmptyArray
(Object[] array) Returnstrue if the specified array is not null and has a length greater than zero.static final <E> E[]
reverse
(E[] array) Reverses the entries in an array.static <E> Object
toArray
(Collection<?> c, Class<E> elementType) Converts the specified collection to an array.static <E> List<E>
Converts the specified array to anArrayList toObjectList
(Object array) Recursively converts the specified array into a list of objects.static String[]
toStringArray
(Collection<?> c) Converts the specified collection to an array of strings.
-
Constructor Details
-
ArrayUtils
public ArrayUtils()
-
-
Method Details
-
append
Appends one or more elements to an array.- Type Parameters:
T
- The element type.- Parameters:
array
- The array to append to.newElements
- The new elements to append to the array.- Returns:
- A new array with the specified elements appended.
-
combine
Combine an arbitrary number of arrays into a single array.- Type Parameters:
E
- The element type.- Parameters:
arrays
- Collection of arrays to combine.- Returns:
- A new combined array, or
null if all arrays arenull .
-
asSet
Converts the specified array to aSet .The order of the entries in the set are the same as the array.
- Type Parameters:
T
- The entry type of the array.- Parameters:
array
- The array being wrapped in aSet interface.- Returns:
- The new set.
-
toArray
Converts the specified collection to an array.Works on both object and primitive arrays.
- Type Parameters:
E
- The element type.- Parameters:
c
- The collection to convert to an array.elementType
- The component type of the collection.- Returns:
- A new array.
-
isArray
Returnstrue if the specified object is an array.- Parameters:
array
- The array to test.- Returns:
true if the specified object is an array.
-
toList
Converts the specified array to anArrayList - Type Parameters:
E
- The element type.- Parameters:
array
- The array to convert.elementType
- The type of objects in the array. It must match the actual component type in the array.- Returns:
- A new
ArrayList
-
toObjectList
Recursively converts the specified array into a list of objects.- Parameters:
array
- The array to convert.- Returns:
- A new
ArrayList
-
copyToList
Copies the specified array into the specified list.Works on both object and primitive arrays.
- Parameters:
array
- The array to copy into a list.list
- The list to copy the values into.- Returns:
- The same list passed in.
-
contains
Returnstrue if the specified array contains the specified element using theString.equals(Object)
method.- Parameters:
element
- The element to check for.array
- The array to check.- Returns:
true if the specified array contains the specified element,false if the array or element isnull .
-
indexOf
Returns the index position of the element in the specified array using theString.equals(Object)
method.- Parameters:
element
- The element to check for.array
- The array to check.- Returns:
- The index position of the element in the specified array, or
-1 if the array doesn't contain the element, or the array or element isnull .
-
toStringArray
Converts the specified collection to an array of strings.Entries are converted to strings using
Object.toString()
.null values remainnull .- Parameters:
c
- The collection to convert.- Returns:
- The collection as a string array.
-
equals
Returnstrue if the following sorted arrays are equals.- Parameters:
a1
- Array #1.a2
- Array #2.- Returns:
true if the following sorted arrays are equals.
-
copyOf
Makes a copy of the specified array.- Type Parameters:
T
- The element type.- Parameters:
array
- The array to copy.- Returns:
- A new copy of the array, or
null if the array wasnull .s
-
isNotEmptyArray
Returnstrue if the specified array is not null and has a length greater than zero.- Parameters:
array
- The array to check.- Returns:
true if the specified array is not null and has a length greater than zero.
-
isEmptyArray
Returnstrue if the specified array is null or has a length of zero.- Parameters:
array
- The array to check.- Returns:
true if the specified array is null or has a length of zero.
-
isEmptyArray
Returnstrue if both specified arrays are null or have a length of zero.- Parameters:
array1
- The array to check.array2
- The array to check.- Returns:
true if the specified array is null or has a length of zero.
-
reverse
Reverses the entries in an array.- Type Parameters:
E
- The element type.- Parameters:
array
- The array to reverse.- Returns:
- The same array.
-