Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing a 2 dimensional array to a single dimensional array in Java

Does anyone know why this doesn't compile?

public class ArrayCompare{

   public static void main (String []args){

      String words= "Hello this is a test";

      String delimiter=" ";
      String [] blocker=words.split(delimiter);

      String [][] grid= new String [100][100];

      grid[0]="Hello";

           if (grid[0].equals(blocker[0])){
                 System.out.print("Done!");
   }
        }
             }

I would like to perform this function of comparison using a 2 dimensional array. I am a newbie! Please help if you can. Thanks in advance!

like image 903
user1299661 Avatar asked Nov 22 '25 12:11

user1299661


1 Answers

Try this:

grid[0][0]="Hello";

grid is a two-dimensional array. For the same reason, you need to do this:

if (grid[0][0].equals(blocker[0]))
like image 76
Óscar López Avatar answered Nov 24 '25 03:11

Óscar López