반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- Intellij
- sklearn
- 자바스크립트
- 비전공자
- crawling
- BS
- 웹앱
- 정보처리기사필기
- Req
- 머신러닝
- AWS
- request
- APPEND
- springboot
- pds
- java
- pandas
- 크롤링
- 백준
- regressor
- lombok
- 정보처리기사
- javascript
- BeautifulSoup
- ensemble
- 자바
- dataframe
- 정처기
- list
- SOUP
Archives
- Today
- Total
No sweet without sweat
[자바/java] 효율적인 배열 복사 System.arrayCopy 본문
728x90
반응형
System.arrayCopy
원하는 부분만 복사할 수 있으며
가독성 측면에서도 효율적이며
불필요한 인스턴스 생성을 방지하여 메모리 자원 낭비를 예방하여 더 빠르게 실행할 수 있다.
System.arrayCopy (src, srcPos, dest, destPos, length);
src - 원본 배열
srcPos - 원본 배열의 복사 시작 위치
dest - 복사할 배열
destPost - 복사할 배열의 복사 시작 위치
length - 복사할 요소의 개수
public class arraycopy {
public static void main(String[] args) {
char[] abc = {'A','B','C','D'};
char[] num = {'0','1','2','3','4','5','6','7','8','9'};
System.out.println(abc);
System.out.println(num);
char [] result = new char[abc.length+num.length];
System.out.println(result);
System.arraycopy(abc, 0, result, 0, abc.length);
System.out.println(result);
System.arraycopy(num, 0, result, abc.length,num.length);
System.out.println(result);
System.arraycopy(abc, 0, num, 0, abc.length);
System.out.println(num);
System.arraycopy(abc, 0, num, 6, 3);
System.out.println(num);
}
}
정답 :
ABCD |
0123456789 |
ABCD |
ABCD0123456789 |
ABCD456789 |
ABCD45ABC9 |
728x90
반응형
'JAVA' 카테고리의 다른 글
[JAVA] - GSON 직렬화 NULL(serializeNulls) (1) | 2023.11.25 |
---|---|
[백준/10430] 자바 나머지 구하기 (0) | 2023.01.04 |
GenericXMLApplicationContext (0) | 2022.07.27 |
스프링 빈 설정 메타 정보 - BeanDefinition (추상화) (0) | 2022.07.26 |
좋은 객체 지향 설계의 5가지 원칙(SOLID) (0) | 2021.12.21 |
Comments