title: How to check if a word is present in a sentence using Java?
body: <p>I am new to programming and working on a function to return true if a word is present in a sentence. I tried the <code>indexOf()</code> method, but then I also came across a certain issue with this approach:</p>
  
  <p>Suppose my sentence is <code>I am a, Java Programmer.</code></p>
  
  <p>If we look for the word <code>ram</code> with the <code>indexOf()</code> method then it will return <code>true</code> because <code>ram</code> is present in <code>Programmer</code> while the correct output should be <code>false</code> as <code>ram</code> is not present as a word but as a pattern.</p>
  
  <p>How can I work around this problem? The code that I am using as of now is:</p>
  
  <pre><code>boolean isPresent(String word, String sentence)
  {
      if(sentence.indexOf(word) &gt;= 0)
          return true;
      else
          return false;
  }
  </code></pre>
  
  <p><strong>NOTE:</strong> The word <code>ram</code> is just an example to show one of the issue with my current approach.It's not that I have to work with <code>ram</code> only all the time.The word can be any like say <code>a</code> which is followed by a comma in above sentence.</p>
  
  <p><strong>UPDATE:</strong> Thanks everyone for providing their comments and solutions. I have selected one as an accepted answer(would have selected more if permitted :-)), but a lot were helpful.</p>