您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

java中如何判断字符串是以什么开头

2025/12/20 11:53:53发布22次查看
函数介绍:
startswith() 方法用于检测字符串是否以指定的前缀开始。
语法:
public boolean startswith(string prefix, int toffset)

public boolean startswith(string prefix)
返回值:
如果字符串以指定的前缀开始,则返回 true;否则返回 false。
推荐免费学习视频:java免费视频教程
endswith() 方法用于测试字符串是否以指定的后缀结束。
语法:
public boolean endswith(string suffix)
返回值:
如果参数表示的字符序列是此对象表示的字符序列的后缀,则返回 true;否则返回 false。
注意,如果参数是空字符串,或者等于此 string 对象(用 equals(object) 方法确定),则结果为 true。
示例如下:
java判断string是否以某个字符串开头:
string mobile = "8618730600000";system.out.println(mobile.startswith("86"));//输出truesystem.out.println(mobile.startswith("886"));//输出false
java判断string是否以某个字符串结尾:
string mobile = "8618730600000";system.out.println(mobile.endswith("0000"));//输出truesystem.out.println(mobile.endswith("8888"));//输出false
想学习更多相关知识请访问:java入门教程
以上就是java中如何判断字符串是以什么开头的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product