1. Using the 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 end and end, this can be done:
if (Str.indexof ("Java")!=-1)
{
string[] str1 = Str.split ("java");
System.out.println (str1.length-1);
}
else
{
System.out.println (0);
}
The above Java lookup string contains the number of substrings to achieve the code is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.