bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Java/Java Reference
Java•Java Reference

Java String contains() Method

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind Java String contains() Method?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___ myStr = "Hello";
3Order

Put the learning moves in the order that makes the concept easiest to apply.

The contains() method checks whether a string contains a sequence of characters.
Definition and Usage
Java String contains() Method

❮ String Methods

Example

String myStr = "Hello";
System.out.println(myStr.contains("Hel"));   // true
System.out.println(myStr.contains("e"));     // true
System.out.println(myStr.contains("Hi"));    // false

Definition and Usage

The contains() method checks whether a string contains a sequence of characters.

Returns true if the characters exist and false if not.

Syntax

public boolean contains(CharSequence
chars )

Parameter Values

ParameterDescription
CharSequence charsThe characters to be searched for

The CharSequence interface is a readable sequence of char values, found in the java.lang package.

Technical Details

Returns:A boolean , indicating whether a sequence of characters exist in the specified string: true - sequence of characters exists false - sequence of characters do not exist
Throws:NullPointerException - if the returned value is null
Java Version:1.5
  • true - sequence of characters exists
  • false - sequence of characters do not exist

Previous

Java String concat() Method

Next

Java String contentEquals() Method