Java String substring() 方法

Java String 类


substring() 方法返回字符串的子字符串。

语法

public String substring(int beginIndex)

或

public String substring(int beginIndex, int endIndex)

参数

  • beginIndex -- 起始索引(包括), 索引从 0 开始。

  • endIndex -- 结束索引(不包括)。

返回值

子字符串。

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

以上程序执行结果为:

返回值 :itzixishi.com
返回值 :itzixishi

Java String 类

本教程仅供参考学习,如用于商业带来的问题,本站概不负责。
关注公众号
关注公众号

©2020 IT自习室京ICP备20010815号