2차원 배열
1.
class ObjArrayEx1 {
public static void main(String[] args) {
int [][]test = new int[2][3];
test[0][0] = 100;
test[0][1] = 200;
test[0][2] = 300;
test[1][0] = 500;
test[1][1] = 600;
test[1][2] = 700;
int [][]a = {{100, 200, 300}, {400, 500, 600}};
for(int i = 0;i < test.length;i++)
for(int j = 0;j < test[i].length;j++)
System.out.println("test["+ i +"]["+ j +"] = "+ test[i][j]);
}
}
* 가변배열
2.
class ObjArrayEx1 {
public static void main(String[] args) {
int [][]test = new int[2][];
test[0] = new int[3];
test[1] = new int[2];
test[0][0] = 100;
test[0][1] = 200;
test[0][2] = 300;
test[1][0] = 500;
test[1][1] = 600;
int [][]a = {{10, 20, 30}, {50, 60}};
}
}
3.
class ObjArrayEx1 {
public static void main(String[] args) {
char []abc = {'A', 'B', 'C', 'D'};
char []number = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
System.arraycopy(abc, 0, number, 0, abc.length);
System.out.println(new String(number));
System.arraycopy(abc, 0, number, 6, 3);
System.out.println(new String(number));
}
}
* abc 배열을 number 배열에 0번째부터 abc.length만큼 붙여넣겠다