title: Problem with assigning an array to other array in Java
body: <pre><code>public class TestingArray {
  
      public static void main(String[] args) {
  
          int iCheck = 10;
          int j = iCheck;
          j = 11;
          System.err.println("value of iCheck "+iCheck);
  
          int[] val1 = {1,2,9,4,5,6,7};
          int[] val2 = val1;
          val2[0] = 200;
          System.err.println("Array Value "+val1[0]);
      }
  }
  </code></pre>
  
  <p>Output:</p>
  
  <blockquote>
    <p><strong>value of iCheck 10<br>
    Array Value 200</strong></p>
  </blockquote>
  
  <p>From the above code, I found that if any array <code>val2</code> is being assigned to another array <code>val1</code> and if we change any value of <code>val2</code> array, the result is as well reflected for the array <code>val1</code> while the same scenario is not with variable assignment.
  Why?</p>