Java String startsWith()方法起什么作用呢?
Java String startsWith()方法的功能说明
startsWith()方法的功能:检测字符串是否使用指定的字符串开头
语法
public boolean startsWith(String prefix)
参数
prefix:待检测的前缀字符串
返回值
- 当字符串是使用指定的字符串开头,则返回true,否则返回false
例
public class testClass {
public static void main(String args[]) {
String Str = new String("The webSite to Java265.com");
System.out.print("Return Value :");
System.out.println(Str.startsWith("The"));
System.out.print("Return Value :");
System.out.println(Str.startsWith("the"));
System.out.print("Return Value :");
System.out.println(Str.startsWith("888"));
}
}
/*
以上代码运行后,将输出以下信息
Return Value :true
Return Value :false
Return Value :false
*/版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


