Any way to declare an array in-line? Any way to declare an array in-line? java java

Any way to declare an array in-line?


m(new String[]{"blah", "hey", "yo"});


Draemon is correct. You can also declare m as taking varargs:

void m(String... strs) {    // strs is seen as a normal String[] inside the method}m("blah", "hey", "yo"); // no [] or {} needed; each string is a separate arg here


Another way to do that, if you want the result as a List inline, you can do it like this:

Arrays.asList(new String[] { "String1", "string2" });