您的位置 首页 技术

java截取字符串后几位字符的方法

java截取字符串后几位字符的方法: java中截取字符串中最后几个字符可以使用String类的substring方法,具体用法参考下方说明: 1、substring(int be…

java截取字符串后几位字符的方法:

java中截取字符串中最后几个字符可以使用String类的substring方法,具体用法参考下方说明:

1、substring(int beginIndex)

substring(int beginIndex)

Returns a new string that is a substring of this string.截取

截取字符串位置beginIndex-1及以后的所有字符,注意字符的起始位置是从0开始的。

例:

String name="weicc-20100107-00001";System.out.println(name.substring(name.length()-5));//输出00001

2、substring(int beginIndex, int endIndex)

substring(int beginIndex, int endIndex)

Returns a new string that is a substring of this string.

截取字符串位置beginIndex到位置endIndex-1的所有字符,此方法前闭后开的,即包括beginIndex位置的字符但是不包括endIndex位置的字符。

例:

String name="weicc-20100107-00001";System.out.println(name.substring(name.length()-5,name.length()));//输出00001

更多java知识请关注java基础教程栏目。

以上就是java截取字符串后几位字符的方法的详细内容,更多请关注24课堂在线网其它相关文章!

本文来自网络,不代表24小时课堂在线立场,转载请注明出处:https://www.24ketang.cn/16925.html

为您推荐

返回顶部