Standard Place for an Empty String Array in the JDK

Posted by Simon B on Stack Overflow See other posts from Stack Overflow or by Simon B
Published on 2010-03-22T15:04:51Z Indexed on 2010/03/22 15:11 UTC
Read the original article Hit count: 376

Filed under:
|
|
|

Hi is there a standard place for accessing empty array constants in the JDK > 1.5.

When I want to do a conversion from a String Collection (e.g. ArrayList)to a String Array I find myself using my own which is defined in my own Constants class:

public static final String[] EMPTY_STRING_ARRAY = new String[0];

And then in my client code something like:

String[] retVal = myStringList.toArray(Constants.EMPTY_STRING_ARRAY);
return retVal;

I was wondering if this is the "idiomatic" of doing it or if I'm missing something I get the impression from the brief search I did that this kind of thing is prevalent in many people's code.

Any ideas, answers, comment (aside from that I shouldn't really use String Arrays) greatly appreciated,

Cheers Simon

© Stack Overflow or respective owner

Related posts about java

Related posts about idioms