如何在Java中将字符串插入2D字符串数组? [英] How to insert a string into a 2D string array in Java?
本文介绍了如何在Java中将字符串插入2D字符串数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Java的新手.
String[][] data = new String[][];
data[0][0] = "Hello";
这不起作用,因此任何人都可以解释其原因以及如何使其起作用吗? 好吧,在C ++/Cli中,它可以完美地工作,但在Java中却不能.
This does not work, so can anyone explain why and how to make it work? Well, in C++/Cli this works perfectly but not in Java.
它说:
找不到符号:类数据
cannot find symbol: class data
推荐答案
在声明数组时,必须指定该数组的行数和列数:
You have to specify the number of rows and columns of the array while declaring it:
String[][] data = new String[2][3];
这将初始化一个包含2行3列的数组.一般来说:
This will initialize an array with 2 rows and 3 columns. In general:
String[][] data = new String[rows][columns];
您还可以省略列数:
String[][] data = new String[2][];
但是要填充它,您将必须分别初始化每一行:
but to be able to fill it, you will have to initialize each row separately:
String[][] data = new String[2][];
data[0] = new String[3];
data[1] = new String[3];
这篇关于如何在Java中将字符串插入2D字符串数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文