basirana
asked on
Array isEmpty
Hi
I am using a normal Array not util.collections
String[] animals = { "bear", "cougar", "wolverine"};
I have two questions. How to find array is empty? How to intialize array as null(without any elements).
Thanks
I am using a normal Array not util.collections
String[] animals = { "bear", "cougar", "wolverine"};
I have two questions. How to find array is empty? How to intialize array as null(without any elements).
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can just copy the condition to your if statement. Then you don't need the method.
i.e.
if (array == null || array.length == 0)
// array is empty
else
// array is not empty
i.e.
if (array == null || array.length == 0)
// array is empty
else
// array is not empty
of course you need to substitute "array" with your variable. In your example:
if (animals == null || animals.length == 0)
// for empty case
else
// for not empty case
if (animals == null || animals.length == 0)
// for empty case
else
// for not empty case
ASKER
Is there anyway we can check inside if condition and find.
Thanks for ur reply.