title: java array pass by reference does not work?
body: <p>I thought almost all languages, including java, pass array into function as reference (modifiable).</p>
  
  <p>But somehow it does not work here, and the <code>testArray</code> is still <code>1,2,3</code> with size of 3.</p>
  
  <p>Strange enough, when if I change <code>result[i] = 2</code> to <code>a[1] =2</code> it works. It did pass by reference.</p>
  
  <p>What is wrong with this code? </p>
  
  <p>At the end, I had <code>a = result</code>; (which update the a). Did result get removed from stack. Is that why I still get to the original <code>a</code>? </p>
  
  <p>I am confused.</p>
  
  <p>Thanks!</p>
  
  <pre><code>class Test
  {
     public static void main(String[] args)
     {
  
        int[] testArray = {1,2,3};
        equalize(testArray, 6);
  
        System.out.println("test Array size :" + testArray.length);
        for(int i = 0; i &lt; testArray.length; i++)
           System.out.println(testArray[i]);
     }
  
     public static void equalize(int[] a, int biggerSize)
     {
        if(a.length &gt; biggerSize)
           throw new Error("Array size bigger than biggerSize");
  
        int[] result = new int[biggerSize];
       // System.arraycopy(a, 0, result, 0, a.length);
       // int array default value should be 0
        for(int i = 0; i &lt; biggerSize; i++)
           result[i] = 2;
  
        a = result;
     }
  }
  </code></pre>