Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Java substring() Method

Java substring() Method

Java String ClassJava String class


The substring() method returns a substring of the string.

Syntax


public String substring(int beginIndex)

或

public String substring(int beginIndex, int endIndex)

Parameters

Return Value

The substring.

Example

public

class

RunoobTest

{

public

static

void

main

(

String

args

[

]

)

{

String

Str

=

new

String

(

"

This is text

"

)

;

System

.

out

.

print

(

"

Return value :

"

)

;

System

.

out

.

println

(

Str

.

substring

(

4

)

)

;

System

.

out

.

print

(

"

Return value :

"

)

;

System

.

out

.

println

(

Str

.

substring

(

4

,

10

)

)

;

}

}

The execution result of the above program is:


返回值 : is text
返回值 : is te

Java String ClassJava String class