网站首页 学习教育 IT科技 金融知识 旅游规划 生活小知识 家乡美食 养生小知识 健身运动 美容百科 游戏知识 综合知识
当前位置:趣知科普吧 > IT科技 > 

javastartswith

栏目: IT科技 / 发布于: / 人气:3.01W

startsWith()方法是属于java下的一个方法,它主要是用于检测字符串是否以指定的前缀开始。

具体的语法格式为:

public boolean startsWith(String prefix,int toffset)


public boolean startsWith(String prefix)

参数:

prefix -- 前缀。

toffset -- 字符串中开始查找的位置。

返回值:

若是字符串以指定的前缀开始,那么返回 true;否则需要返回false。

javastartswith

参考范例:

示例代码:

public class Test {    public static void main(String args[]) {        String Str = new String("www.runoob.com");         System.out.print("返回值 :" );        System.out.println(Str.startsWith("www") );         System.out.print("返回值 :" );        System.out.println(Str.startsWith("runoob") );         System.out.print("返回值 :" );        System.out.println(Str.startsWith("runoob", 4) );    }}

输出结果:

返回值 :true返回值 :false返回值 :true
推荐内容