Search code examples
javaarraysmaze

How do I pass an array parameter to an object from a constructor?


I need to pass a String[][] parameter from a class that I made, for example:

public class Maze {

    String maze[][];
    int rows;
    int columns;
    int xStart;
    int yStart;

    public Maze(String xMaze[][], int xRows, int xColumns, int xxStart, int xyStart) {     
        maze = xMaze;
        rows = xRows;
        columns = xColumns;
        xStart = xxStart;
        yStart = xyStart;
    }

I need to call the String maze[][] in my main class but the only way I know to do so is by calling it null. What's a way I can initialize it by calling it as an object? My example of the null is below.

static Maze maze = new Maze(null,0,0,0,0);

Is there a way to call the String[][] rather than just a null? Seems like such a simple question yet I can't find the answer.


Solution

  • Maze maze = new Maze(new String[2][2],0,0,0,0);