1. Use indexof method:
public class Test11 {private static int counter = 0;/** * @param args */public static void main(String[] args) {String str ="sdSS**&HGJhadHCASch& ^^";int i = stringNumbers(str);System.out.println(i);}public static int stringNumbers(String str){if (str.indexOf("java")==-1){return 0;}else if(str.indexOf("java") != -1){counter++;stringNumbers(str.substring(str.indexOf("java")+4));return counter;}return 0;}} 2. If the substring is not a string with the same beginning and end, it can also be implemented like this:
if(str.indexOf("java") != -1){String[] str1 = str.split("java");System.out.println(str1.length-1);}else {System.out.println(0);}The above java search for the number of substrings in strings is the entire content shared by the editor. I hope it can give you a reference and I hope you can support Wulin.com more.