// 사용법
package exercise.chapter_20;
public class ArrayDeclaration {
public static void main(String[] args) {
int[] intArr = new int[10];
int[] intArr2 = new int[]{1,2,3,4};
int[] intArr3 = {1,2,3,4};
}
}
// 접근하기
package exercise.chapter_20;
public class ArrayIndex {
public static void main(String[] args) {
int[] studentScores = {90, 87, 88, 75, 99, 65};
int score1 = studentScores[0];
}
}
// 반복문 사용
package exercise.chapter_20;
public class ArrayFor {
public static void main(String[] args) {
int[] studentScores = {90, 87, 88, 75, 99, 65};
for (int i = 0; i < studentScores.length; i++) {
System.out.printf("$d", studentScores[i]);
}
}
}
같은 물건에 여러 이름이 붙는 것이다.
같은 메모리 주소를 바라보는 것이다.
package exercise.chapter_21;
public class ArrayCopy {
public static void main(String[] args) {
int a = 5;
int b = a;
int[] arr1 = {1,2,3,4};
int[] arr2 = arr1;
}
}
실제 물건도 이름도 다른 게 만든다.
즉 새로운 메모리에 새로 값을 할당하는 것이다.
package exercise.chapter_21;
public class TwoDimensionArrayCopy {
public static void main(String[] args) {
int[][] arr = {
{1,2,3,4},
{5,6,7,8},
{9,10,11,12}
};
int[][] arr2 = arr.clone();
}
}