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

In the example above, we used

In the example above, we used

Java String ClassJava String class


The contains() method is used to determine whether the string contains the specified character or sequence of characters.

Syntax


public boolean contains(CharSequence chars)

Parameters

Return Value

Returns true if the string contains the specified character or sequence, otherwise returns false.

Example

The following example checks whether Runoob contains a character or a sequence of characters:

Example

public

class

Main

{

public

static

void

main

(

String

[

]

args

)

{

String

myStr

=

"

Runoob

"

;

System

.

out

.

println

(

myStr

.

contains

(

"

Run

"

)

)

;

System

.

out

.

println

(

myStr

.

contains

(

"

o

"

)

)

;

System

.

out

.

println

(

myStr

.

contains

(

"

s

"

)

)

;

}

}

The execution result of the above program is:


true
true
false

Java String ClassJava String class