두 개의 작은 배열을 모아 새로운 객체 배열을 만들고 싶습니다.
null 일 수 없지만 크기는 0 일 수 있습니다.
이 두 가지 방법 중 하나를 선택할 수 없습니다. 동등합니까 아니면 하나 더 효율적입니까 (예 : 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 typesbyte [], Object [], char [] 이면 정말 더 빠릅니까? 다른 모든 경우에는 유형 검사가 실행됩니다. 이것은 내 경우이므로 동등합니다.
또 다른 연결된 질문에서 그들은 the size matters a lot크기가> 24 인 경우 system.arraycopy ()가 이기고 10보다 작은 경우 수동 for 루프가 더 좋다고 말합니다 .
이제 정말 혼란 스러워요.



arraycopy()가장 확실하게 더 빠른 네이티브 호출입니다.