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 s = abacacac, subs
s = abacacac, subs
To count the matching substring
System.out.println(s.split(substr, -1).length-1);
To get replaced string- you can use following code
System.out.println(Pattern.compile(s).matcher(substr).replaceAll(""));