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 -