title: Modifying an Array Passed as an Argument in Java
body: <p>Why does this work, displaying <code>array</code> in sorted order?:</p>
  
  <pre><code>Integer[] array={7,5,9,3,6,0,2,4};
  
  MergeSort.mergeSort(array,0,7);
  
  System.out.println(Arrays.toString(array));
  </code></pre>
  
  <p>Specifically, why does passing <code>array</code> to a public static void method <code>mergeSort</code> end up modifying the array itself? I thought that Java protected from this. For example this code:</p>
  
  <pre><code>  public static void main(String[] args){
      int c=2;
      change(c);
      System.out.print(c);
    }
    public static void change(int c){
      c=4;
    }
  </code></pre>
  
  <p>returns 2 instead of 4. I am confused why Java allows you to modify an array passed as a parameter, but not an int</p>