In the example above, we used
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
-
chars -- The character or string to be tested for.
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 class