title: Java: Check to see if String.contains matches exact word
body: <p>Trying to check if a text file contains a string, however i just want the exact string, for example.</p>
  
  <blockquote>
    <p>String.contains(CA).</p>
  </blockquote>
  
  <p>But lets say the text file </p>
  
  <ol>
  <li>CA CALIFORNIA</li>
  <li>NP CALIPER</li>
  <li>WX ABDICATE</li>
  </ol>
  
  <p>What would be the best method to just check for "CA" exactly, i only want to return true for (1), but in my case i'll get true for all three.</p>
  
  <pre><code>while (scanner.hasNextLine()) {
          String line = scanner.nextLine();
          if(line.contains(Source)) {
              hasSource = true;
              break;
          }
          lineCounter++;
      }
  </code></pre>