I have added some values to drawPoints[][] and then made an ArrayList Object points that is
ArrayList points=new ArrayList();
points.add(drawPoints);
Now i want to retrieve the value of drawPoints from points, how can i do that?
You need to access first drawPoints in your ArrayList with
int[][] tmp = (int[][]) points.get(0);
and then you will be able to get values with for example
tmp[0][1];
Here's a little example of a program that prints values of two 2D arrays that are stored in an ArrayList:
int[][] drawPoints = new int[2][2];
int[][] drawPoints2 = new int[2][2];
drawPoints[0][0] = 1;
drawPoints[0][1] = 2;
drawPoints[1][0] = 3;
drawPoints[1][1] = 4;
drawPoints2[0][0] = 5;
drawPoints2[0][1] = 6;
drawPoints2[1][0] = 7;
drawPoints2[1][1] = 8;
ArrayList<Object> points=new ArrayList<Object>();
points.add(drawPoints);
points.add(drawPoints2);
for(Object tab : points){
int[][] tmp = (int[][]) tab;
for(int i=0;i < tmp.length;i++){
for(int j=0;j<tmp[i].length;j++){
System.out.println(tmp[i][j]);
}
}
System.out.println("------------");
}
tmp variable and print their values.You just put a 2d array into the first slot of an ArrayList. So you'd write:
int[][]somePoints = (int[][])points.get(0);
if i understand correctly:
points.get(0); // get the first item (at index 0) from the list