check empty array java code example
Example 1: check if array is empty java
if (myArray == null || myArray.length == 0) { }
Example 2: java empty array
String [] names = new String[0];
// or
int [] ages = {}
Example 3: isempty for arrays
Object arr[] = new Object[10];
boolean empty = true;
for (Object ob : arr) {
if (ob != null) {
empty = false;
break;
}
}
Example 4: isempty for arrays
arr = new int[0];
if (arr.length == 0) {
System.out.println("array is empty");
}