Hy,
I'm a bit new to JAVA, and having a big problem. While I'm adding elements to a List<int[]>
the result will be a List full of with the same value.
Why JAVA is working like this?
Here is the code:
// Global variables
private static int rows = 20;
private static int columns = 30;
private static String[][] labirinth = new String[rows][columns];
private static List<int[]> walls = new ArrayList<int[]>();
// Local variables inside a function
int[] wall = new int[2];
if(row - 1 <= rows && labirinth[row-1][column] == "*")
{
wall[0] = row-1;
wall[1] = column;
walls.add(wall);
}
if(row + 1 <= rows && labirinth[row+1][column] == "*")
{
wall[0] = row+1;
wall[1] = column;
walls.add(wall);
}
if(column - 1 <= columns && labirinth[row][column-1] == "*")
{
wall[0] = row;
wall[1] = column-1;
walls.add(wall);
}
if(column + 1 <= columns && labirinth[row][column+1] == "*")
{
wall[0] = row;
wall[1] = column+1;
walls.add(wall);
}
At the end the walls
variable will hold the last result of wall
at multiple times.
Thanks for the help!