判断前缀:
public boolean startsWith(String prefix, int toffset)
或
public boolean startsWith(String prefix)
其中:
- prefix – 前缀。
- toffset – 字符串中开始查找的位置。
返回值为true 或 false。
例:
String startCode = "北京欢迎您";
System.out.println(startCode.startsWith("北京"));
System.out.println(startCode.startsWith("欢迎"));
System.out.println(startCode.startsWith("欢迎",2));
输出结果:
true
false
true