首页javastringJava Data Type - 如何从字符串获取子字符串

Java Data Type - 如何从字符串获取子字符串

我们想知道如何从字符串获取子字符串。

We can use the substring() method to get a sub-part of a string.

We can takes the start index as the parameter and returns a substring beginning at the start index to the end of string.

We can also takes the start index and the end index as parameters.

It returns the substring beginning at the start index and one less than the end index.

For example,

String s1 = "Hello".substring(1); // s1 has "ello" String s2 = "Hello".substring(1, 4); // s2 has "ell"