title: Java String-buffer - How to count occurrence of specific word in a string
body: <p>All,</p>
  
  <p>I need to count the specific word from a string in stringbuffer. i have made a program (please see below) to count a specific char in a string but not sure how to do this for a word. for example... my string is "Cat can kill mouse but mouse can not kill cat". I need to count how many times word cat occurred in the string.</p>
  
  <p>thank you so much for your help.
  Kind Regards,</p>
  
  <p>Viku</p>
  
  <p>public static void main(String[] args) {</p>
  
  <pre><code>    StringBuffer myBuffer = new StringBuffer("a is the first vowel in a e i o u");
      int charCount = 0;
      for(int i =0 ; i&lt; myBuffer.length(); i++){
          if(myBuffer.charAt(i) == 'a' || myBuffer.charAt(i) == 'e' || 
                  myBuffer.charAt(i) == 'i' || myBuffer.charAt(i) == 'o' ||
                  myBuffer.charAt(i) == 'u'){
              charCount++;
          }
      }
      System.out.println(nL + "Compute of Vowels in String: " + charCount);
  
  
  
  
  }
  </code></pre>
  
  <p>}</p>