将2d字符数组复制到另一个2d字符数组中

时间:2021-12-11 21:30:16

I am trying to copy a 2d character array into another 2d character array via a constructor of a class. The original array is read in from a an external text file and then converted into a 2d array. However I can't seem to read in this 2d array from another class. The code that I am trying is listed below, it is the constructor of the search class. Thank You.

我试图通过类的构造函数将2d字符数组复制到另一个2d字符数组中。原始数组从外部文本文件读入,然后转换为2d数组。但是我似乎无法从另一个类中读取这个2d数组。我正在尝试的代码如下所示,它是搜索类的构造函数。谢谢。

char[][] arraytwo;

public search(char[][] inarray)
{
    for(int i = 0; i < inarray.length; i++)
    {
        String row = inarray.;
        for(int j = 0; j < inarray[i].length; j++)
        {
            arraytwo[i][j] = inarray.charAt(c);
        }
    }
}

2 个解决方案

#1


1  

The statement inside your inner for loop should be:

内部for循环中的语句应该是:

arraytwo[i][j] = inarray[i][j];

You index an array using the same syntax whether you're reading from it or writing to it. (charAt is a method you'd call on a String, not an array.)

无论是从中读取数据还是写入数组,都可以使用相同的语法对数组进行索引。 (charAt是您在String上调用的方法,而不是数组。)


Also, you don't need the line

此外,您不需要该行

String row = inarray.;

There's a syntax error on that line anyway.

无论如何,该行都存在语法错误。

#2


0  

the code is malformed, you copied that wrong:

代码格式错误,你复制了错误:

String row = inarray.;

#1


1  

The statement inside your inner for loop should be:

内部for循环中的语句应该是:

arraytwo[i][j] = inarray[i][j];

You index an array using the same syntax whether you're reading from it or writing to it. (charAt is a method you'd call on a String, not an array.)

无论是从中读取数据还是写入数组,都可以使用相同的语法对数组进行索引。 (charAt是您在String上调用的方法,而不是数组。)


Also, you don't need the line

此外,您不需要该行

String row = inarray.;

There's a syntax error on that line anyway.

无论如何,该行都存在语法错误。

#2


0  

the code is malformed, you copied that wrong:

代码格式错误,你复制了错误:

String row = inarray.;