javaarraysarrayobjecttype-2-dimension

Using a 2-dimensional object array


This is my 2-dimensional array:

String[][] theMaze = new String[row][column];

How to use it in this method?

public void ruteToX(String[][] theMaze){
    // call theMaze and process in this method
}

Solution

  • Assuming I understood your question in the right sense.

    I'll show you an example of passing an array to the method ruteToX(...).

    public class Example
    {
    
    String[][] theMaze = new String[5][5];
    public void ruteToX(String[][] theMaze)
    { 
    //call theMaze and process in this method 
    }
    
    public static void main(....)
    {
       Example ob=new Example();
       ob.ruteToX(ob.theMaze);
       //passed the value of reference or the pointer to the function ruteToX(...)
    }
    }
    

    How is it passed?

    When you pass an array, the value of it's pointer or reference in the memory is passed which means if you make any changes to the parameter array in the method, the actual array will also face the same changes (since they are the same-same reference).