title: How to test if a position on a 2D grid contains an object in an array?
body: <p>I was making a game where there is a 2d grid with walls, players, and enemies. I have a file with the 2d grid with each as a different character. While reading the file, I assigned a 2d array to contain the values of the walls as they will not move, but I created a new enemy and new player when the character for either was read. Now I'm trying to display the players and enemies and I cannot figure out how to. Here's my code:</p>
  <pre><code>private char[][] cells;
  private Player player;
  private Lion[] lions;
  
  public boolean hasPlayer(int row, int col)
  {
      return false;       // needs fixing
  }
  
  public boolean hasLion(int row, int col)
  {
  if(cells[row][col] == '&amp;') return true;
      else return false;      // needs fixing
  }
  
  public void display{
  for(int i = 0; i &lt; ROWS; i++)  
  {
    for(int j = 0; j &lt; COLS; j++) 
    {
      if(hasPlayer(i,j)){
        System.out.print(Main.BLUE + &quot;P &quot;);
      }
              
      else if(hasLion(i,j)){
        System.out.print(Main.YELLOW + &quot;&amp; &quot;);
      }
     }
    }    
   }
  </code></pre>