Java substring(int beginIndex, int endIndex) 方法

返回到:Java 介绍String类

substring() 方法返回字符串的子字符串。可以理解为字符串切片。

语法

public String substring(int beginIndex)

public String substring(int beginIndex, int endIndex)

参数

  • beginIndex — 起始索引(包括)。
  • endIndex — 结束索引(不包括)。

注意:这两个参数都为int类型

返回值

子字符串。

实例

public class Test {
    public static void main(String args[]) {
    	String Str = new String("www.web176.com");

    	System.out.print("返回值 :" );
    	System.out.println(Str.substring(4) );

    	System.out.print("返回值 :" );
    	System.out.println(Str.substring(4, 10) );
	}
}

返回到:Java 介绍String类

作者:terry,如若转载,请注明出处:https://www.web176.com/java_api/19628.html

(0)
打赏 支付宝 支付宝 微信 微信
terryterry
上一篇 2023年5月5日
下一篇 2023年5月5日

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注