public class TestArray {
private static Point[][] mPoints = new Point[3][4];
public static void main(String[] args) {
//第一行
mPoints[0][0] = new Point(0, 0);
mPoints[0][1] = new Point(0, 1);
mPoints[0][2] = new Point(0, 2);
mPoints[0][3] = new Point(0, 3);
//第二行
mPoints[1][0] = new Point(1, 0);
mPoints[1][1] = new Point(1, 1);
mPoints[1][2] = new Point(1, 2);
mPoints[1][3] = new Point(1, 3);
//第三行
mPoints[2][0] = new Point(2, 0);
mPoints[2][1] = new Point(2, 1);
mPoints[2][2] = new Point(2, 2);
mPoints[2][3] = new Point(2, 3);
System.out.println("mPoints.length===========" + mPoints.length + "行");
for (int i = 0; i < mPoints.length; i++) {//遍历行
Point[] mPoint = mPoints[i];
System.out.println("mPoint.length==========" + mPoint.length + "列");
for (int j = 0; j < mPoint.length; j++) {//遍历列
System.out.println(i + "行======" + j + "列===值为===" + mPoint[j].toString());
}
}
}
static class Point {
int x;
int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
@Override
public String toString() {
return "Point{" +
"x=" + x +
", y=" + y +
'}';
}
}
}
打印结果:
mPoints.length===========3行
mPoint.length==========4列
0行======0列===值为===Point{x=0, y=0}
0行======1列===值为===Point{x=0, y=1}
0行======2列===值为===Point{x=0, y=2}
0行======3列===值为===Point{x=0, y=3}
mPoint.length==========4列
1行======0列===值为===Point{x=1, y=0}
1行======1列===值为===Point{x=1, y=1}
1行======2列===值为===Point{x=1, y=2}
1行======3列===值为===Point{x=1, y=3}
mPoint.length==========4列
2行======0列===值为===Point{x=2, y=0}
2行======1列===值为===Point{x=2, y=1}
2行======2列===值为===Point{x=2, y=2}
2行======3列===值为===Point{x=2, y=3}