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