title: Java Two Dimensional Array passed to method and not changed
body: <p>This question about a 2D array being passed into a method came up in class. Can someone explain why the original array d is unchanged after a call to doStuff() ?   I debugged the code and saw that the method was reversing the values, but then when returned, the original array remained unchanged.  I thought passing arrays into a method and changing values in that method would affect the original array. Here that is not the case,  the original array is unchanged.  My first thought was the orignal would be reversed.  But no.</p>
  
  <ol start="5">
  <li><p>Initialize the array d and call doStuff as
  follows:</p>
  
  <pre><code>    int d[][] = { {-1,0,1},  
                    {5,6,7},  
                    {2,3,4} };  
      doStuff(d);    
  
  
      public static void doStuff (int [][] frst)    
      {    
          int len = frst.length;    
          int sec[][] = new int[len] [];    
          for (int j=0; j&lt;len; j++)  
          {        
              sec[j] = frst[len –j -1];     
          }       
          frst = sec;      
      }    
  </code></pre></li>
  </ol>