Top Description Constructors Methods
org.assertj.core.util

public Class Arrays

extends Object
Class Inheritance
Static Imports
java.lang.String.format, java.lang.reflect.Array.getLength, java.util.Arrays.stream, .Collections.emptyList, .Objects.requireNonNull, java.util.stream.Collectors.toList, org.assertj.core.util.Lists.newArrayList, .Preconditions.checkArgument

Utility methods related to arrays.
Authors
Alex Ruiz, Joel Costigliola, Florent Biville

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static <
the type of the array to return.
T
>
T[]

Returns:

an array containing the given arguments.
array
(T...
the values to store in the array.
values
)

Returns an array containing the given arguments.

public static int[]

Returns:

an int[].
array
(AtomicIntegerArray
the AtomicIntegerArray to convert to int[].
atomicIntegerArray
)

Returns an int[] from the AtomicIntegerArray, null if the given atomic array is null.

public static long[]

Returns:

an long[].
array
(AtomicLongArray
the AtomicLongArray to convert to long[].
atomicLongArray
)

Returns an long[] from the AtomicLongArray, null if the given atomic array is null.

public static <
the type of elements of the array.
T
>
T[]

Returns:

an T[].
array
(AtomicReferenceArray<T>
the AtomicReferenceArray to convert to T[].
atomicReferenceArray
)

Returns an T[] from the AtomicReferenceArray, null if the given atomic array is null.

public static List<Object>

Returns:

the values of the given Object as a List<Object>.
asList
(Object
array passed as an object to support both primitive and Object array
array
)

Get the values of any array (primitive or not) into a List<Object>.

public static Object[]

Returns:

the values of the given Object as a Object[].
asObjectArray
(Object
array passed as an object to support both primitive and Object array
array
)

Get the values of any array (primitive or not) into a Object[].

public static <
the type of elements of the array.
T
>
boolean

Returns:

true if the given array has only null elements or is empty, false otherwise.
hasOnlyNullElements
(T[]
the given array. It must not be null.
array
)

Returns true if the given array has only null elements, false otherwise.

public static boolean

Returns:

true if the given object is not null and is an array, otherwise false.
isArray
(Object
the given object.
o
)

Indicates whether the given object is not null and is an array.

public static boolean
public static boolean
private static <T> boolean
isEmpty(T[] array)

public static <
the type of elements of the array.
T
>
boolean

Returns:

true if the given array is null or empty, otherwise false.
isNullOrEmpty
(T[]
the array to check.
array
)

Indicates whether the given array is null or empty.

public static boolean
public static <
the type of elements of the array.
T
>
List<T>

Returns:

all the non-null elements in the given array. An empty list is returned if the given array is null.
nonNullElementsIn
(T[]
the given array.
array
)

Returns all the non-null elements in the given array.

public static IllegalArgumentException
public static <T> T[]
prepend(T first, T... rest)

public static int
sizeOf(Object array)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Arraysback to summary
private Arrays()

Method Detail

arrayback to summary
public static <T> T[] array(T... values)

Returns an array containing the given arguments.

Parameters
<T>
the type of the array to return.
values:T[]

the values to store in the array.

Returns:T[]

an array containing the given arguments.

Annotations
@SafeVarargs
arrayback to summary
public static int[] array(AtomicIntegerArray atomicIntegerArray)

Returns an int[] from the AtomicIntegerArray, null if the given atomic array is null.

Parameters
atomicIntegerArray:AtomicIntegerArray

the AtomicIntegerArray to convert to int[].

Returns:int[]

an int[].

arrayback to summary
public static long[] array(AtomicLongArray atomicLongArray)

Returns an long[] from the AtomicLongArray, null if the given atomic array is null.

Parameters
atomicLongArray:AtomicLongArray

the AtomicLongArray to convert to long[].

Returns:long[]

an long[].

arrayback to summary
public static <T> T[] array(AtomicReferenceArray<T> atomicReferenceArray)

Returns an T[] from the AtomicReferenceArray, null if the given atomic array is null.

Parameters
<T>
the type of elements of the array.
atomicReferenceArray:AtomicReferenceArray<T>

the AtomicReferenceArray to convert to T[].

Returns:T[]

an T[].

Annotations
@SuppressWarnings:unchecked
asListback to summary
public static List<Object> asList(Object array)

Get the values of any array (primitive or not) into a List<Object>.

Parameters
array:Object

array passed as an object to support both primitive and Object array

Returns:List<Object>

the values of the given Object as a List<Object>.

Exceptions
IllegalArgumentException:
it the given Object is not an array.
asObjectArrayback to summary
public static Object[] asObjectArray(Object array)

Get the values of any array (primitive or not) into a Object[].

Parameters
array:Object

array passed as an object to support both primitive and Object array

Returns:Object[]

the values of the given Object as a Object[].

Exceptions
IllegalArgumentException:
it the given Object is not an array.
hasOnlyNullElementsback to summary
public static <T> boolean hasOnlyNullElements(T[] array)

Returns true if the given array has only null elements, false otherwise. If given array is empty, this method returns true.

Parameters
<T>
the type of elements of the array.
array:T[]

the given array. It must not be null.

Returns:boolean

true if the given array has only null elements or is empty, false otherwise.

Exceptions
NullPointerException:
if the given array is null.
isArrayback to summary
public static boolean isArray(Object o)

Indicates whether the given object is not null and is an array.

Parameters
o:Object

the given object.

Returns:boolean

true if the given object is not null and is an array, otherwise false.

isArrayEmptyback to summary
public static boolean isArrayEmpty(Object array)
isArrayTypePrimitiveback to summary
public static boolean isArrayTypePrimitive(Object o)
isEmptyback to summary
private static <T> boolean isEmpty(T[] array)
isNullOrEmptyback to summary
public static <T> boolean isNullOrEmpty(T[] array)

Indicates whether the given array is null or empty.

Parameters
<T>
the type of elements of the array.
array:T[]

the array to check.

Returns:boolean

true if the given array is null or empty, otherwise false.

isObjectArrayback to summary
public static boolean isObjectArray(Object o)
nonNullElementsInback to summary
public static <T> List<T> nonNullElementsIn(T[] array)

Returns all the non-null elements in the given array.

Parameters
<T>
the type of elements of the array.
array:T[]

the given array.

Returns:List<T>

all the non-null elements in the given array. An empty list is returned if the given array is null.

notAnArrayOfPrimitivesback to summary
public static IllegalArgumentException notAnArrayOfPrimitives(Object o)
prependback to summary
public static <T> T[] prepend(T first, T... rest)
Annotations
@SuppressWarnings:unchecked
sizeOfback to summary
public static int sizeOf(Object array)