Get the number of times a specified string appears in another string in Java for your reference. The specific content is as follows
/** * @param args */ public static void main(String[] args) { String srcText = "Hello World"; String findText = "e"; int num = appearNumber(srcText, findText); System.out.println(num); } /** * Get the number of times the specified string appears* * @param srcText Source string* @param findText String to be found* @return */ public static int appearNumber(String srcText, String findText) { int count = 0; Pattern p = Pattern.compile(findText); Matcher m = p.matcher(srcText); while (m.find()) { count++; } return count; }The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.