I have a simple class:
public class XYPoint {
public int x, y;
}
And a 2D array that contains arrays of Point objects:
(-2, 2)(-1, 2)(0, 2)(1, 2)(2, 2)
(-2, 1)(-1, 1)(0, 1)(1, 1)(2, 1)
(-2, 0)(-1, 0)(0, 0)(1, 0)(2, 0)
(-2, -1)(-1, -1)(0, -1)(1, -1)(2, -1)
(-2, -2)(-1, -2)(0, -2)(1, -2)(2, -2)
The correspond ids are:
0 1 2 3 4
5 6 7 8 9
10 11 12 13 14
15 16 17 18 19
20 21 22 23 24
Let's say I want to get the element at id 0
, then it will return -2, 2
. If I want to get from 6
, it will return -1, 1
and so on.
Is there any way I can get an element without looping the entire array?