<分区>
我已经看到,当您像这样声明数组时,它们是有效的:
int[] myarray = {2,4,6,8,10}; //Notice the brackets are with the type
当你这样声明它们时:
int myarray[] = {2,4,6,8,10}; //Here the brackets are with the array name
那么哪一种是声明数组的正确方法,第一种和第二种之间有什么区别(如果有的话)。
谢谢。
<分区>
我已经看到,当您像这样声明数组时,它们是有效的:
int[] myarray = {2,4,6,8,10}; //Notice the brackets are with the type
当你这样声明它们时:
int myarray[] = {2,4,6,8,10}; //Here the brackets are with the array name
那么哪一种是声明数组的正确方法,第一种和第二种之间有什么区别(如果有的话)。
谢谢。
最佳答案
根本没有功能上的区别。然而,将括号与类型放在一起被认为是好的做法:
int[] myarray = {2,4,6,8,10};
关于java - 声明数组的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20800056/