To print empty elements:
for (int i = 0; i < arr.length; i++) {
if (arr[i] == null || arr[i].trim().isEmpty()) {
System.out.println("Element " + i " + " is null or empty.");
}
}
The print non-empty elements:
for (int i = 0; i < arr.length; i++) {
if ( arr[i] != null && !arr[i].trim().isEmpty())) {
System.out.println(arr[i]);
}
}
0
solved How to avoid printing empty array elements? [closed]