title: How can I check if the elements of an ArrayList equal another value in Java?
body: <p>Specifically if said <code>ArrayList</code> is made out of String elements, and I'd like to check each letter in those <code>Strings</code>. This is what I tried, but obviously it doesn't work:</p>
  
  <pre><code>public void fillBoard()
      {
          board = new char[ROW][COL];
  
          for (String s: words){
  
              for(int rows = 0; rows &lt; board.length; rows++)
              {
                  for(int cols = 0; cols &lt; board[rows].length; cols++)
                  {
                      if(!s.equals(board[rows][cols])) 
                      {                          
                          board[rows][cols] = randomChar();
                      }
                  }   
  
              }
          }
      }
  </code></pre>
  
  <p>I was trying to compare each char in a <code>2D</code> array to the letters in the <code>Strings</code> that make up the <code>ArrayList</code>.</p>
  
  <p>The <code>ArrayList</code> is <code>ArrayList&lt;String&gt; words = new ArrayList&lt;String&gt;();</code> and it's populated by the users as they enter words when prompted. So it can look like {"hello","goodbye","words",...}</p>
  
  <p><code>board</code> is a 2D char array, the dimensions are defined by user input</p>
  
  <p>It's then populated by random chars by this method:</p>
  
  <pre><code>public char randomChar()
      {
          char alphabet[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
                  'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
                  'y', 'z'};
  
          return alphabet[(char)(alphabet.length * Math.random())];
      }
  
  }
  </code></pre>
  
  <p>The intention is that the <code>char board[][]</code> array may also contain randomly placed words, and when the board is updated, all the letters that aren't part of a <code>string</code> in the <code>words ArrayList</code> are randomized again, keeping the words that the user input and where then placed in the array, kind of like updating the board in a battleship program after each turn.</p>