welcome to java".subString(0,10)返回是什么?

来源:百度知道 编辑:UC知道 时间:2024/09/28 14:14:40
如题

您的语句会返回含有10个字符的字符串--“welcome to”
原理:sunString函数获得参数1到参数2(包含参数2)的所有字符,连接成新的字符串并返回。

详细使用您可以参考文档:
public String substring(int beginIndex,
int endIndex)返回一个新字符串,它是此字符串的一个子字符串。该子字符串从指定的 beginIndex 处开始,一直到索引 endIndex - 1 处的字符。因此,该子字符串的长度为 endIndex-beginIndex。
示例:
"hamburger".substring(4, 8) returns "urge"
"smiles".substring(1, 5) returns "mile"
参数:
beginIndex - 开始处的索引(包括)。
endIndex - 结束处的索引(不包括)。
返回:
指定的子字符串。

welcome to
0是起始位置 10是结束位置
截取[起始位置~结束位置-1]的字符

从下标为0的开始数 到10个前一位截取。
welcome to //后面无空格

welcome to 后面没空格

"welcome to"