hanif s hanif s - 5 months ago 73
Android Question

how to check the string array is empty or null android?

I am new to java. Am unable to check for null. Could you enlighten me on this?
I have string array which has no elements.

I tried this code

String[] k = new String[3];
if(k==null){
System.out.println(k.length);
}

Answer Source

Very precisely

if(k!=null && k.length>0){
    System.out.println(k.length);
}else
    System.out.println("Array is not initialized or empty");

k!=null would check array is not null. And StringArray#length>0 would return it is not empty[you can also trim before check length which discard white spaces].

Some related popular question -