开发者

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜