Are there array creation expressions in Java?
In C#, I can use an expression like this开发者_运维百科:
void doStuffOnArray(int[] array) {...}
doStuffOnArray(new int[] {0, 2, 4, 6, 8});
is there an equivalent one-liner in Java? Or do I have to stick with
int[] temp = {0, 2, 4, 6, 8};
doStuffOnArray(temp);
?
Exactly the same syntax works:
doStuffOnArray(new int[] { 1, 2, 3, 4, 5 });
Yes, the syntax is exactly the same in java! :)
精彩评论