假设我像这样初始化一个数组:
int[] anArray = {
100, 200, 300,
400, 500, 600,
700, 800, 900, 1000
};
是否保证元素总是按照我在初始化时键入的相同顺序插入?例如:100,200,300,400,500,600,700,...,1000
?
最佳答案
是的,这是由规范保证的(参见 JLS 10.6):
The variable initializers immediately enclosed by the braces of the array initializer are then executed from left to right in the textual order they occur in the source code. The n'th variable initializer specifies the value of the n-1'th array component.
关于java - 初始化的数组是否保留其顺序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34733278/