//使用regionMatches(),startsWith(),endsWith();
public class Example5_2 {
public static void main(String[] args) {
int number = 0;
String s = "student;entropy;engage;english;client";
for(int k=0;k<s.length();k++){
if(s.regionMatches(k, "en", 0, 2)){ //使用s.regionMatches(k, "en", 0, 2)
number++;
}
}
System.out.println("number = "+number);
String s1 = "english";
String s2 = "eng";
String s3 = "ish";
String s4 = "gli";
System.out.println("s1.startsWith(s2) = "+s1.startsWith(s2));
System.out.println("s1.endsWith(s3) = "+s1.endsWith(s3));
System.out.println("s1.startsWith(s3,2) = "+s1.startsWith(s4,2));
}
}