Question

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.

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);
        }
    }
}
Was it helpful?

Solution

The statement inside your inner for loop should be:

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.)


Also, you don't need the line

String row = inarray.;

There's a syntax error on that line anyway.

OTHER TIPS

the code is malformed, you copied that wrong:

String row = inarray.;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top