title: Is it better to use System.arraycopy(...) than a for loop for copying arrays?
body: <p>I want to create a new array of objects putting together two smaller arrays.</p>
  
  <p>They can't be null, but size may be 0.</p>
  
  <p>I can't chose between these two ways: are they equivalent or is one more efficient (for example system.arraycopy() copies whole chunks)?</p>
  
  <pre><code>MyObject[] things = new MyObject[publicThings.length+privateThings.length];
  System.arraycopy(publicThings, 0, things, 0, publicThings.length);
  System.arraycopy(privateThings, 0, things,  publicThings.length, privateThings.length);
  </code></pre>
  
  <p>or </p>
  
  <pre><code>MyObject[] things = new MyObject[publicThings.length+privateThings.length];
  for (int i = 0; i &lt; things.length; i++) {
      if (i&lt;publicThings.length){
          things[i] = publicThings[i]
      } else {
          things[i] = privateThings[i-publicThings.length]        
      }
  }
  </code></pre>
  
  <p>Is the only difference the look of the code?</p>
  
  <p><strong>EDIT:</strong> thanks for linked question, but they seem to have an unsolved discussion:</p>
  
  <p>Is it truly faster if <code>it is not for native types</code>: byte[], Object[], char[]? in all other cases, a type check is executed, which would be my case and so would be equivalent... no?</p>
  
  <p>On another linked question, they say that <code>the size matters a lot</code>, for size >24 system.arraycopy() wins, for smaller than 10, manual for loop is better...</p>
  
  <p><em>Now I'm really confused.</em></p>