Java substring() Method
The substring() method returns a substring of the string.
Syntax
public String substring(int beginIndex)
或
public String substring(int beginIndex, int endIndex)
Parameters
-
beginIndex -- The start index (inclusive); indexes start at 0.
-
endIndex -- The end index (exclusive).

Return Value
The substring.
Example
public
class
RunoobTest
{
public
static
void
main
(
String
args
[
]
)
{
String
Str
=
new
String
(
"
This is text
"
)
;
System
.
out
.
(
"
Return value :
"
)
;
System
.
out
.
println
(
Str
.
substring
(
4
)
)
;
System
.
out
.
(
"
Return value :
"
)
;
System
.
out
.
println
(
Str
.
substring
(
4
,
10
)
)
;
}
}
The execution result of the above program is:
返回值 : is text
返回值 : is te
Java String class