Not really. There are actually a surprising number of uses for zero-length arrays. They come up quite often in Reflection, for instance.
Why would it be useful in Reflection or anything for that matter?
"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
Joined: Jan 03, 2006
Originally posted by Stan James: Check the args in a main() method started with no args and see if a zero length array is useful.
It is useful to know that there was no command line arguments, but it doesn't explain why creating a zero length array in your code has any value.
Joined: Jan 29, 2003
We can communicate the same thing to other methods that the JVM communicates to us in main(). Maybe you want an array of widgets sold in New Jersey last week, and there weren't any. Would you rather have to check the count first, handle an exception, or accept a empty array? This speaks to me pretty clearly about what will happen if there are zero or a hundred...
They are definately useful. They define a list with no items. If I have a series of steps to execute - lets just say a To-Do list - and that list is an array. What happens when I get to a day with nothing to do? Would I rather have a null value and have to check the null, adjust behavior, etc?
If there's one thing to learn, if your method returns any sort of collection - attempt to return an empty collection rather than null, unless it actually IS null.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus