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

Java endsWith() Method

Java endsWith() Method

Java String ClassJava String class


The endsWith() method is used to test whether the string ends with the specified suffix.

Syntax


public boolean endsWith(String suffix)

Parameters

Return Value

If the character sequence represented by the argument is a suffix of the character sequence represented by this object, returns true; otherwise returns false. Note that if the argument is the empty string, or is equal to this String object (determined by the equals(Object) method), the result is true.

Example

public

class

Test

{

public

static

void

main

(

String

args

[

]

)

{

String

Str

=

new

String

(

"

Runoob Tutorial:www.runoob.com

"

)

;

boolean

retVal

;

retVal

=

Str

.

endsWith

(

"

runoob

"

)

;

System

.

out

.

println

(

"

Return value =

"

retVal

)

;

retVal

=

Str

.

endsWith

(

"

com

"

)

;

System

.

out

.

println

(

"

Return value =

"

retVal

)

;

}

}

The execution result of the above program is:


返回值 = false
返回值 = true

Java String ClassJava String class