利用substring()与length()
String str = "abcdefg";
str.substring(0,str.length()-1);看不懂这段代码length()是长度的意思substring()是什么意思?
8 回答

青天大老爷HAO
TA贡献1条经验 获得超2个赞
上例 str.length(); 是指str字符串的长度;
而 str.substring()是截取str这个字符串的方法
substring()有二个重载方法
1、substring(int beginindex) 表示从你规定的字符串下标为 beginindex 位置开始截取往后取值。
2、substring(int beginindex , int endindex)表示从你规定的字符串下标为 beginindex 位置开始截取往后取值 到你规定末尾要截取到的下标位置。

qq_昼绽_0
TA贡献82条经验 获得超17个赞
length():返回字符串长度的方法。
substring(int index1,index2):放回一个字符串,取值为——从使用该方法的字符串的 第(index1)个字符到第(index2-1)个字符。(由于技术原因,科学家从0开始计数)

coward2
TA贡献2条经验 获得超0个赞
substring
public String substring(int beginIndex)
返回一个新的字符串,它是此字符串的一个子字符串。该子字符串始于指定索引处的字符,一直到此字符串末尾
添加回答
举报
0/150
提交
取消