谁能看懂? 求指教
public class StringTest2 {
public static void main(String[] args) {
String str = "hanbasdnbafllgnbahjnbakqqqqlnbaxnbai";
String regex = "nba";
int count = getCount(str, regex);
int count2 = getCount2(str, regex);
System.out.println(count);
}
public static int getCount(String maxString, String minString) {
int count = 0;
int index = maxString.indexOf(minString);
while (index != -1) {
count++;
maxString = maxString.substring(index + minString.length());
index = maxString.indexOf(minString);}
return count;
} |
|