Reputation: 1165
I was wondering on how to initialize a point array when you declare it. I was thinking it would be similar to
int[] num = {4,7,8};
But I realized that points have x and y values so how would you do the above for point arrays?
Upvotes: 1
Views: 10641
Reputation: 53576
You mean, something like
int[][] num = new int[][] {
new int[] {1, 2, 3},
new int[] {4, 5, 6},
new int[] {7, 8, 9},
};
int x = 1, y = 0;
System.out.println( num[y][x] ); // -> 2
?
Upvotes: 1
Reputation: 285405
Consider doing something like:
Point[] myPoints = {
new Point(1, 2),
new Point(3, 4)
}
This is a specific case of the general reference array.
MyType[] myTypeArray = {
new MyType(...),
new MyType(...),
// .... etc
}
Upvotes: 13