*배열
int[[] arr = new int[10]; // 10이 배열의 크기로 이때 index는 0 ~ 9까지.
배열의 크기는 arr.length로 사용. (반복문에서 배열 사용 시 사용)
배열은 int[] s = {1,2,3}; 이런식으로 바로 초기화해서 사용 가능.
*for - each루프
int[] list = {1, 2, 3};
for ( int a : list } {
System.out.println(a);
}
*2차원 배열
int[][] list = new int[3][5]; //list[0][0] ~ list[2][4]
*ArrayList _ 가볌 크기의 배열
자바의 전통적인 배열보다 편리. 자바 전통 배열은 크기 지정후 변경 불가한 단점이 있다.
ArrayList>String> list = new ArrayList<>();
list.add("milk"); _ 데이터 삽입
list.set(1, "apple"); _ 특정 위치의 원소 변경
list.remove(2); _ 데이터 삭제
list.get(1); _ 해당 인덱스의 원소 반환
list.size(); _ 저장된 데이터 개수
'알고리즘' 카테고리의 다른 글
JAVA 개념 정리 (1) (0) | 2024.01.02 |
---|