0

I am trying to delete all the same data in an 2D array; for example;

0 1 3 4 1 4
0 2 3 4 2 1
0 2 3 2 2 1

if the user types the coordinate as (0,1); all the data that equals to 0 should be null; However, my code will just the delete the data which I typed in.

int a =Integer.valueOf(scan.next());
int b= Integer.valueOf(scan.next());
for(int i=0;i<rows;i++){
    for (int j=0;j<clos;j++){
        if(BubbleWordl.world[i][j]==BubbleWorld.world[a][b]){
            BubbleWorld.world[i][j]=null;
        }
    }
}
Nicolas Filotto
  • 43,537
  • 11
  • 94
  • 122

1 Answers1

0

I guess that BubbleWordl.world is an array of Integer class instances, not an array of int primitives.

Use .equals for comparing Integers:

if(BubbleWordl.world[i][j].equals(BubbleWorld.world[a][b])) {
   ...

See Java: Integer equals vs. == for details.

Community
  • 1
  • 1
Alex Shesterov
  • 26,085
  • 12
  • 82
  • 103