<1.8. Arrays>
- 1차원 배열 생성밥법의 예는 int [] a =new int[10]; 또는 int a [] = new int[10]; 이다.
- 초기화안하면 0, null, false으로 초기화된다.
- 배열 범위 벗어난 index에 접근했을 경우 C에서는 그냥 실행시키지만, Java에서는 에러 발생시킨다.
- 어떤 타입이든 배열 a의 길이는 a.length로 알 수 있다. 메소드가 아닌 것에 주의하자.
- 배열을 복사하는 방법은 두 가지다. =를 이용하는 것과 arraycopy()를 이용하는 것이다.
- =를 사용하면 주소를 복사하는거여서 같은 배열을 가리키게 된다!(메모리 할당 필요X)
- arraycopy는 값을 복사시키는거고 서로 다른 배열이다(메모리 할당 필요O)
- 2차원 배열의 생성방법 예는 int a[][] = new int[4][3]; 또는 int [][] a = new int[4][3]; 이다.
(이 경우에 a.length는 4, a[0].length는 3)
<EX 소스코드>
github.com/HoYoungChun/Java_Language_Lecture/tree/master/EX06
HoYoungChun/Java_Language_Lecture
Contribute to HoYoungChun/Java_Language_Lecture development by creating an account on GitHub.
github.com
'JAVA > JAVA_Lecture' 카테고리의 다른 글
| Lecture 08: Object-Oriented Programming (2) (0) | 2020.10.08 |
|---|---|
| Lecture 07: Object-Oriented Programming (1) (0) | 2020.10.08 |
| Lecture 05: Java Programming Basics (4) (0) | 2020.10.08 |
| Lecture 04: Java Programming Basics (3) (0) | 2020.09.14 |
| Lecture 03: Java Programming Basics (2) (0) | 2020.09.10 |