您的位置:首页 > 编程语言 > Java开发

《Java编程技巧1001条》第377条:了解Java的数组声明,

2017-12-21 14:25 344 查看



《Java编程技巧1001条》第10部分 使用数组存储数据第377条 , 了解Java的数组声明 

377 Declaring an Array in Java
377 在Java中声明一个数组

As you havelearned, creating an object is a two-step process. To start, you must firstdeclare the object. Then, you must make an instance of that object. In Java,arrays are objects. Therefore, you must first declare an array, and then createit.
In Java, you can declare an array in two ways. The first syntaxplaces the bracketbraces [][] on the variable name. The following codedemonstrates an integer array declaration:
你已知道了,创建一个对象是一个两步的过程. 开始时,必须先声明这个对象. 然后,为此对象创建一个实例. 在Java中,数组也是对象,所以必须先要声明一个数组,然后再建立它.在Java中,声明一个数组可以用两种办法.第一种方法是在变量名后加一对或几对括号[].以下语句是(一维)整型数组的声明:int myarray[];
 
Thealternative declaration syntax places the bracketbraces [] on the variable datatype. The following code demonstrates the type name:
另一种句法是在变量数据类型后加对括号[].以下语句是采用这种句法的声明:int[] myarray;
 
Notice thatthe size of the array is not part of the declaration. You define an arrays sizewhen you create the array.
注意,数组的大小不属于声明的一部分内容. 你在后面创建数组的实例时必须定义数组的大小.
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: