Package org.fest.util
Class Arrays
java.lang.Object
org.fest.util.Arrays
Utility methods related to arrays.
- Author:
- Alex Ruiz, Joel Costigliola
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T[]
array
(T... values) Returns an array containing the given arguments.static String
Returns theString
representation of the given array, ornull
if the given object is eithernull
or not an array.static <T> boolean
hasOnlyNullElements
(T[] array) Returnstrue
if the given array has onlynull
elements,false
otherwise.static boolean
Indicates whether the given object is notnull
and is an array.static <T> boolean
isNullOrEmpty
(T[] array) Indicates whether the given array isnull
or empty.static <T> List
<T> nonNullElementsIn
(T[] array) Returns all the non-null
elements in the given array.
-
Method Details
-
isArray
Indicates whether the given object is notnull
and is an array.- Parameters:
o
- the given object.- Returns:
true
if the given object is notnull
and is an array, otherwisefalse
.
-
isNullOrEmpty
public static <T> boolean isNullOrEmpty(T[] array) Indicates whether the given array isnull
or empty.- Type Parameters:
T
- the type of elements of the array.- Parameters:
array
- the array to check.- Returns:
true
if the given array isnull
or empty, otherwisefalse
.
-
array
public static <T> T[] array(T... values) Returns an array containing the given arguments.- Type Parameters:
T
- the type of the array to return.- Parameters:
values
- the values to store in the array.- Returns:
- an array containing the given arguments.
-
format
Returns theString
representation of the given array, ornull
if the given object is eithernull
or not an array. This method supports arrays having other arrays as elements.- Parameters:
array
- the object that is expected to be an array.- Returns:
- the
String
representation of the given array.
-
nonNullElementsIn
Returns all the non-null
elements in the given array.- Type Parameters:
T
- the type of elements of the array.- Parameters:
array
- the given array.- Returns:
- all the non-
null
elements in the given array. An empty list is returned if the given array isnull
. - Since:
- 1.1.3
-
hasOnlyNullElements
public static <T> boolean hasOnlyNullElements(T[] array) Returnstrue
if the given array has onlynull
elements,false
otherwise. If given array is empty, this method returnstrue
.- Type Parameters:
T
- the type of elements of the array.- Parameters:
array
- the given array. It must not be null.- Returns:
true
if the given array has onlynull
elements or is empty,false
otherwise.- Throws:
NullPointerException
- if the given array isnull
.- Since:
- 1.1.3
-