Notice
Recent Posts
Recent Comments
«   2024/09   »
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
Archives
Today
Total
관리 메뉴

충분히 쌓여가는

5.6 배열(Array) 타입 - new 초기화할 경우 기본 값 본문

이것이 자바다/05 참조 타입

5.6 배열(Array) 타입 - new 초기화할 경우 기본 값

빌드이너프 2024. 3. 31. 18:31
타입[] 변수 = new 타입[길이];

 

타입[] 변수 = null;
변수 = new 타입[길이];

 

예시

int[] intArray = new int[5];

 

 

new 연산자로 배열을 처음 생성하면 배열 항목은 기본값으로 초기화 된다

byte[] 0
short[] 0
int[] 0
long[] 0L
   
char[] '\u0000'
   
float[] 0.0F
double[] 0.0

 

클래스[] null
인터페이스[] null

 

 

예시

int[] scores = new int[5];
0 1 2 3 4
0 0 0 0 0

 

String[] names = new String[5];
0 1 2 3 4
null null null null null