title: How to find the count of substring in java
body: <p>I am trying to find the count of the substring in a big string of length 10000 characters. Finally I need to remove all the substring in it.
  example <code>s = abacacac, substr = ac</code>, <code>num of occurrence = 3</code> and final string is <code>s = ab</code>. My code is below, its not efficient for data of length 10000 characters. </p>
  
  <pre><code>int count =0;
  while(s.contains(substr))
  {
     s= s.replaceFirst(substr,"");
     count++;    
  }
  </code></pre>