Java String startsWith(String prefix, int toffset)方法具有什么功能呢?

Java教程王 Java教程 发布时间:2021-04-08 15:33:27 阅读数:17179 1

String startsWith(String prefix, int toffset)方法的功能

       startsWith(String prefix, int toffset)方法的功能:检测字符串指定位置上的开头字符串

语法 

     public boolean startsWith(String prefix, int toffset)

参数

  • prefix:待检测的前缀字符串
  • toffset:检测字符串的起始位置 

返回值

   当字符串指定区间,为prefix开头时,则返回true,否则返回false 

public class testClass {

    public static void main(String args[]) {
        String Str = new String("Welcome to java265.com");

        System.out.print("Value :");
        System.out.println(Str.startsWith("java265"));

        System.out.print("Value :");
        System.out.println(Str.startsWith("java265", 11));
    }
}
/*
以上代码运行后,将输出以下信息

Value :false
Value :true

*/ 
版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。

本文链接: https://www.Java265.com/JavaCourse/177.html

最近发表

热门文章

好文推荐

Java265.com

https://www.java265.com

站长统计|粤ICP备14097017号-3

Powered By Java265.com信息维护小组

使用手机扫描二维码

关注我们看更多资讯

java爱好者