难道一个初始化数组保留其顺序? [英] Does an initialized Array retain its order?

查看:98
本文介绍了难道一个初始化数组保留其顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我初始化数组有点像这样的:

Say that I initialize an Array somewhat like this:

int[] anArray = { 
    100, 200, 300,
    400, 500, 600, 
    700, 800, 900, 1000
};

时能够保证所有的元素将在我的初始化输入相同的顺序总是插入?例如: 100,200,300,400,500,600,700,......,1000

推荐答案

是的,这是由规范担保(见的JLS 10.6 ):

Yes this is guaranteed by the specification (see JLS 10.6):

变量初始化立即的括号括起来
  数组初始化,然后从留在文本执行向右
  为了它们出现在源$ C ​​$ C。第n变量初始化
  指定第n-1阵列组件的值

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.

这篇关于难道一个初始化数组保留其顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆