What does this mean when creating multidimensional arrays?

-1 Developer John · September 4, 2014
Hi! First off, I'm new here. I think the forums here are really well organized. The website is fantastic as well (nice translucent title boxes). Anyways, I'm still wondering what this means when creating multidimensional arrays:

public static void display(int x[][]){

Even after about 2 tutorials, I still don't understand what it means. Can someone please help me?:D


Post a Reply


Oldest  Newest  Rating
0 Developer John · September 6, 2014
Ok thanks! I understand now. 8-)
+2 Çağlan Turgut · September 6, 2014
The array that x has the value of won't be changed when you change x because x is just a copy of the array. Its not linked to it or something.

Example Code:

public class mainclass 

    public static void main(String args[])
        int y = 19; //Create your main variable called y
        System.out.println(y); //print the variable y
        display(y);//Call the method that edits the duplicate of y
        System.out.println(y); //print the variable y again to see if it has been changed.

    public static void display(int x)
        x = 99;

0 Developer John · September 5, 2014
Why would x not change after editing it? :O
0 Çağlan Turgut · September 4, 2014
He is calling the display method from the main method with:


that means that x equals to the value of the "firstarray" that has been declared in the main method. Which means in this case:

int x [][]={{8,9,10,11}{12,13,14,15}};

something like that.

Then the display method does the calculations etc.(whatever..) and the code continues from the next line of main method which is:

System.out.println("This is the second array");

Keep that in mind: Even if you edit the value of x, the value of "firstarray" won't be edited so I think we can say that x is used to store data while the process continues. Then when we call the display method with the "secondarray" x will be equal to the "secondarray"
-1 Pere Garau Burguera · September 4, 2014
It's a method that takes a multidimensional array of integers as a parameter and prints it out on screen. The variable x is used inside the method as the 'generic' variable of the parameter. 

So, for example, if you do


this method will display all the firstarray values, and the x then is gonna be 'the same' as firstarray. Then, the same would happen with secondarray. 
0 Developer John · September 4, 2014
Is x used to store data?
0 Çağlan Turgut · September 4, 2014
He is creating a method which takes in a multidimensional array of integers called "x" as a parameter.
  • 1

Java / Android Development


Very popular language used to create desktop applications, website applets, and Android apps.

Bucky Roberts Administrator