欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > > 文章正文

java中字符串截取,调用substring()方法,javasubstring

来源: javaer 分享于  点击 4380 次 点评:35

java中字符串截取,调用substring()方法,javasubstring


substring() 方法返回字符串的子字符串。在java中 substring()方法有两种用法,

第一种

public String substring(int beginIndex)

第二种

public String substring(int beginIndex, int endIndex)

参数的意思

  • beginIndex -- 起始索引(包括)。

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

第一种:返回一个新的字符串,它是此字符串的一个子字符串。该子字符串从指定索引处的字符开始,直到此字符串末尾。
第二种:返回一个新字符串,它是此字符串的一个子字符串。该子字符串从指定的 beginIndex 处开始,直到索引 endIndex - 1 处的字符。因此,该子字符串的长度为 endIndex-beginIndex。

示例代码:
public static void main(String[] args) {
	String Str = new String("hello wrold");
		 
        System.out.print("返回值 :" );
        System.out.println(Str.substring(4) );
 
        System.out.print("返回值 :" );
        System.out.println(Str.substring(4, 10) );
}
运行结果:

返回值 :o wrold
返回值 :o wrol


最后的最后  :各位看官,看完的觉得有用又不嫌麻烦的就给个赞或者给个评论呗,嫌麻烦的也请麻烦一下给个赞呗,想踩一脚的,手下留情,码字不易,且看且珍惜,(我的大刀已经饥渴难耐了)



相关文章

    暂无相关文章

用户点评