例如我正在制作一个刽子手程序,而且我想要制作一个名为words
的数组,而单词中的项目则是单词
这是我认为你可以做的:
String[] words = new String [15];
words[1] = String[] MILK = {"M","I","L","K"};
words[2] = String[] CLOTH = {"C","L","O","T","H"};
答案 0 :(得分:6)
您可以使用数组数组
String[][] arrays = new String[][] { array1, array2, array53};
答案 1 :(得分:3)
您想要的是多维数组。这些基本上是数组内的数组。
您的代码应如下所示:
String[][] words = new String [15][];
words[1] = new String[] {"M","I","L","K"};
words[2] = new String[] {"C","L","O","T","H"};
有关文档,请参阅this website
答案 2 :(得分:3)
我认为你在寻找:
String[][] words = new String [15][];
String[] milk = words[0] = new String[] {"M","I","L","K"};
String[] cloth = words[1] = new String[] {"C","L","O","T","H"};
答案 3 :(得分:1)
您将使用的是二维数组。
将其视为一个看起来像这样的矩阵
[][][][]
[][][][]
[][][][]
[][][][]
每个方框都包含一个字母。
使用以下代码初始化
String[][] words = new String [x][y];
其中x是单词(行)的总数,y是字母(列)的总数。