I have this
String p[] = null;
I need to check whether its size/length is null
or not. Something like
if (p.length == null)
But it does not work.
You cannot check length of null
. Also, length
returns an int
which can never be null
. Just do
if (p == null) {
// There is no array at all.
} else if (p.length == 0) {
// There is an array, but there are no elements.
}
Or just instantiate it instead of keeping it null
.
String[] p = new String[0];
Then you can do:
if (p.length == 0) {
// There are no elements.
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With