JAVA/배열( array )
-
배열 - 2JAVA/배열( array ) 2023. 5. 3. 10:56
구분 내용 생성 시기 / 소멸 시기 Method Area byte code literal final static 생성 : 프로그램 시작 소멸 : 프로그램 종료 Heap 객체(object) 배열... > new로 생성되는 것들 생성 : new 생성시 소멸 : reference가 끊길 때 (Garbage Collection에 의해 자동 소멸) Stack 지역변수 매개변수 생성 : 블럭 안에서 선언될 때 소멸 : 블럭이 끝날 때 배열에 for문 사용과 enhanced for문 사용시의 차이점 기본적으로 두 개의 구문 모두 배열을 순회할 수 있지만, 결정적인 차이가 존재한다 enhanced for문은 기본적으로 배열의 소요를 꺼내어 변수에 담아서 사용하기 때문에 배열의 원소를 직접 변경하는 것이 불가능하다~! ..
-
배열이란?JAVA/배열( array ) 2023. 5. 3. 09:54
동일한 타입의 여러개의 데이터를 담는 집합 자료형 키워드 정리 : 동일 타입, 여러개의 데이터 배열의 선언 배열을 new로 생성한뒤에는 자동초기화 가 됨. 숫자타입들은 --> 0으로 boolean타입은 --> false 로 객체타입(Object) 타입은 --> null 로. // 선언 // 자료타입[] 변수이름; int[] arr; // 선언 + 초기화 int[] korea = new int[3]; // 배열의 크기 3 korea[0] = 100; korea[1] = 90; korea[2] = 80; // 선언 + 초기화 int[] korea = new int[]{100, 90, 80}; // 선언 + 초기화 int[] korea = {100, 90, 80};// new 는 알아서 해줌 배열의 길이 배열..