2つの小さな配列をまとめてオブジェクトの新しい配列を作成したいと思います。
nullにすることはできませんが、サイズは0にすることができます。
これら2つの方法を選択することはできません。それらは同等ですか、それとももう1つ効率的ですか(たとえば、system.arraycopy()はチャンク全体をコピーします)?
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);
または
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]
}
}
唯一の違いはコードの外観ですか?
編集:リンクされた質問に感謝しますが、彼らは未解決の議論を持っているようです:
it is not for native typesバイト[]、オブジェクト[]、文字[]の場合、本当に高速ですか?他のすべてのケースでは、タイプチェックが実行されます。これは私のケースなので、同等です...いいえ?
別のリンクされた質問で、彼らはthe size matters a lot、サイズが> 24のsystem.arraycopy()が勝つ場合、10より小さい場合は、手動forループの方が良いと述べています...
今、私は本当に混乱しています。



arraycopy()ネイティブコールであり、確実に高速です。