开发者

Are there array creation expressions in Java?

开发者 https://www.devze.com 2023-03-27 14:49 出处:网络
In C#, I can use an expression like this开发者_运维百科: void doStuffOnArray(int[] array) {...}

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! :)

0

精彩评论

暂无评论...
验证码 换一张
取 消