private final String[] okFileExtensions = new String[] { "csv" };
Would someone please explain why {} is written after a String array declaration?
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s an array of one element. In this case containing the
String"csv".When written as part of a declaration, this can be written in a more concise form:
Multiple-element arrays use commas between values. There needn’t be any values at all.
It may be worth noting that although the reference is final the array is not. So you can write:
A way to get around this is to switch to collections and use an unmodifiable implementation:
JDK8 is intended to have enhancement to collections that will make this more concise. Probably
ListandSetliterals within the language. Possibly:Collections should generally be preferred over arrays (for reference types).