java - Use of array of zero length -


For example, we can construct an array like this:

  New element Type [0];  

I have seen such a construction, but I do not understand why it may be useful.

Say an example, you have a function

  public string [] GetFileNames {{/ code> 

Imagine getting some file names that you do not find any file name satisfying criteria What will you return? You have 2 options - the version with either empty empty , or 0-size array 0-size array is better because your The caller does not need to check NULL and can process the array in a compatible way - say, in a loop (which will be empty in this case).

One lesson on this


Comments