You can check the bytecode:
1.
public static void main(java.lang.String[]);
Code:
0: iconst_0
1: anewarray #2 // class java/lang/String
4: astore_1
5: aload_1
6: invokestatic #3 // Method foo:([Ljava/lang/String;)V
9: return
2.
public static void main(java.lang.String[]);
Code:
0: iconst_0
1: anewarray #2 // class java/lang/String
4: invokestatic #3 // Method foo:([Ljava/lang/String;)V
7: return
The only difference is that in (2), no references are stored (astore_1
) and none need to be loaded (aload_1
). This will almost certainly not cause a performance difference (and you shouldn't worry about such minuscule optimizations anyway), but you might as well use option (2) if you're not going to reference a
again in the program (as you mentioned in your comment) and there is no readability infringement.
I think the readability component is quite important: I would much rather create a variable to store the array (even if I'll never reference this variable more than once) than have one super-long, unreadable line. Of course, in your example, there is no issue with readability, but it's something to consider when more complicated situations arise.