title: Count the number of Occurrences of a Word in a String
body: <p>I am new to Java Strings the problem is that I want to count the Occurrences of a specific word in a String. Suppose that my String is:</p>
  
  <pre><code>i have a male cat. the color of male cat is Black
  </code></pre>
  
  <p>Now I dont want to split it as well so I want to search for a word that is "male cat". it occurs two times in my string!</p>
  
  <p>What I am trying is:</p>
  
  <pre><code>int c = 0;
  for (int j = 0; j &lt; text.length(); j++) {
      if (text.contains("male cat")) {
          c += 1;
      }
  }
  
  System.out.println("counter=" + c);
  </code></pre>
  
  <p>it gives me 46 counter value! So whats the solution?</p>