isNotEmpty
is a static method of the ArrayUtils
class that checks whether the given array is not empty or not null.
Application of the isNotEmpty
function will result in true
, as the array is not empty.
Application of the isNotEmpty
function will result in false
, as the array is empty.
ArrayUtils
is defined in theApache Commons Lang
package. To addApache Commons Lang
to the Maven Project, add the following dependency to thepom.xml
file.
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
For other versions of the commons-lang package, refer to the Maven Repository.
You can import the
ArrayUtils
class as follows.
import org.apache.commons.lang3.ArrayUtils;
public static boolean isNotEmpty(final int[] array)
final int[] array
: array to check for non-emptiness.This method returns true
if the array is not empty or not null
. Otherwise it returns false
.
import org.apache.commons.lang3.ArrayUtils; public class Main { public static void main(String[] args) { int[] array = {1,2,3,4,5,2,3,2,2,4}; boolean check = ArrayUtils.isNotEmpty(array); System.out.println("Array is not empty - " + check); int[] array1 = new int[0]; check = ArrayUtils.isNotEmpty(array1); System.out.println("Array1 is not empty - " + check); } }
Array is not empty - true
Array1 is not empty - false
RELATED TAGS
CONTRIBUTOR
View all Courses