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

《Java 编程技巧1001条》 第386条: 声明多维数组

2017-12-22 08:52 495 查看

《Java 编程技巧1001条》第10章 用数组存储数据 第386条 声明多维数组 

386Declaring Multidimensional Arrays
386 声明多维数组

Tip 385discussed multidimensional arrays. To declare a multidimensional arrays withina Java program, you simply specify additional sets of bracketbraces. Forexample, to declare a two-dimensional array, you declare the array with twosets of bracketbraces, as shown:
TIP 385讨论了多维数组. 要在Java程序中声明多维数组,你只需写出更多对的括号.例如, 要声明两维数组,你只需写出两对括号,如下:int TicTacToe[][];
 
You canalso use the alternative declaration syntax that you learned in Tip 377 todeclare multidimensional arrays by placing the extra bracketbraces after theprimitive or object type. The following code demonstrates an alternativedeclaration of a two-dimensional array:
你同样可以利用TIP 377中所介绍的句法来声明多维数组,把附加的括号对放在基本类型或对象类型之后. 以下这一语句说明了声明2维数组的另一种方法:int[][] TicTacToe;
 
You mayeven mix the two types of declarations., as demonstrated by the following code:demonstrates how to do this:
你甚至可以把两种声明的形式混起来使用,如以下语句所表示的那样:int[] TicTacToe[];
 
Each ofthese examples declares an equivalent two-dimensional array reference.
以上每一个例子都是声明了相互等价的一个2维数组.

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: