您好,欢迎访问一九零五行业门户网

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

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截取字符串后几位字符的方法的详细内容。
其它类似信息

推荐信息