Possible Duplicate:
What is the usage of array of zero length?
What is the purpose of zero length arrays.Are they of any use or just like that because the syntax allows?
If you have a function that takes an array, and you want to give it an array with nothing in it, you pass an zero-length array.
If you read an array from an external source, and it happens to not have any items, you'll get an zero-length array.
Assuming you mean in Java, you can iterate over zero-length arrays without any problem but you can't do this, if the variable is set to null
.
String[] myArr = new String[0];
for (String str : myArr) {
// do something here
}
If you set myArr
to null
instead, you'd get a NullPointerException
in this loop.
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