배열이란?
- 동일한 자료형의 순차적 자료 구조
- 인덱스 연산자 []를 이용하여 빠른 참조가 가능
- 물적 위치와 논리적 위치가 동일
- 배열의 순서는 0부터 시작
- 자바에서는 객체 배열을 구현한 ArrayList를 많이 활용한다.
배열의 선언과 초기화
- 배열 선언하기
- int[] arr1 = new int[10];
- int arr2[] = new int[10];
- 배열 초기화 하기
- 배열은 선언과 동시에 자료형에 따라 초기화 됨(정수는 0, 실수는 0.0, 객체는 null)
- 필요에 따라 초기값을 지정할 수 있음
- int[] numbers = new int[] {10, 20, 30}; // 개수 생략해야 함
- int[] numbers = {10, 20, 30}; // new int[] 생략 가능
- int[] ids; ids = new int[] {10, 20, 30} // 선언 후, 배열을 생성하는 경우는 new int[] 생략할 수 없음
- 배열 사용하기
- [] 인덱스 연산자 활용 -> 배열요소가 저장된 메모리의 위치를 연산하여 찾아 줌



- length 메소드 사용시 주의 / 인덱스 주소와 배열의 길이가 헷갈릴 수 있음.
.png)
enhanced for문



.png)
2차원 배열
다차원 배열
- 2차원 이상으로 구현된 배열
- 평면(2차원 배열)이나 공간(3차원 배열)을 활용한 프로그램 구현


- 생성과 동시에 초기화시 행마다 열을 다르게 할 수 있다.


