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
}
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
}
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).
When passing in the array, in the previous method (whatever is running before 'ruteToX') call the method and pass the array in using just the variable name.
public void previousMethod(){
ruteToX(theMaze);
}
public void ruteToX(String[][] theMaze){
// call theMaze and process in this method
}
EDIT: In addition, once in the method you can either use the array as is or create a new array equal to the original array.
public void ruteToX(String[][] theMaze){
String[][] secondMaze = theMaze;
}