Java String substring()
方法有兩個變體,它返回該字串的子字串。 子字串以指定索引處的字元開頭,並且如果給出第二個參數,則擴展到此字串的末尾或最多為endIndex - 1
索引處之間的字元。
語法
以下是此方法的語法 -
public String substring(int beginIndex)
參數
beginIndex
- 開頭索引(包括)。
返回值
- 指定的子字串。
示例
public class Test {
public static void main(String args[]) {
String Str = new String("Welcome to xuhuhu.com");
System.out.print("Return Value :");
System.out.println(Str.substring(11, 17));
}
}
執行上面示例代碼,得到以下結果:
Return Value :zaixian
上一篇:
Java String類
下一篇:
Java快速入門