title: Does Java pass-by-value for arrays?
body: <p>I have a question regarding the concept of Java using pass-by-value. I do a lot of programming in C but I am very inexperienced with Java so I have been writing some code to learn a bit more about it. I have read many stack-overflow questions regarding whether there is ever any pass-by-reference, the answer seems to be that Java always uses pass-by-value (with the slight deviation being it passes references to objects by value).</p>
  
  <p>With this in mind I’ve managed to properly confuse myself, I don’t understand how the following example can be an instance of pass-by-value. I would appreciate an explanation as to the internal Java workings that I don’t understand.</p>
  
  <p>I have the following code:</p>
  
  <pre><code>byte[] myByteArray = {23, 45, 67};
  myHashMap.put(myKey, new TestClass(100, myByteArray, myOtherByteArray));
  Arrays.fill(myByteArray, (byte)0);
  </code></pre>
  
  <p>Where <code>myHashMap</code> is a <code>ConcurrentHashMap</code> and <code>TestClass</code> is defined:</p>
  
  <pre><code>public class TestClass
  {
    public final int number;
    public final byte[] byte1;
    public final byte[] byte2;
  
    public TestClass(int a, byte[] b, byte[] c)
    {
      number = a;
      byte1 = b;
      byte2 = c;
    }
  }
  </code></pre>
  
  <p>When I use the debugger to step through the code I can see that the <code>byte1</code> variable stored in <code>TestClass</code> (And subsequently in the <code>ConcurrentHashMap</code>) is altered by the <code>Arrays.fill</code> call, my question is ... why? </p>
  
  <p>When instantiating a new <code>TestClass</code> am I not passing <code>myByteArray</code> by value?</p>