How can I initialize a String array with length 0 in Java?

As others have said,

new String[0]

will indeed create an empty array. However, there’s one nice thing about arrays – their size can’t change, so you can always use the same empty array reference. So in your code, you can use:

private static final String[] EMPTY_ARRAY = new String[0];

and then just return EMPTY_ARRAY each time you need it – there’s no need to create a new object each time.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)