Curriculum
Course: Java Basic
Login

Curriculum

Java Basic

Java Home

0/1

Java Introduction

0/1

Java Get Started

0/1

Java Syntax

0/1

Java Comments

0/1

Java Type Casting

0/1

Java Operators

0/1

Java Booleans

0/1

Java Switch

0/1

Java Break / Continue

0/1

Java Errors and Exception

0/1
Text lesson

contentEquals()

Example

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

Definition and Usage

The contentEquals() method examines a string to determine if it exactly matches the sequence of characters in the specified string or StringBuffer.

It returns true if the characters match and false if they do not

Syntax

One of the following options:

public boolean contentEquals(StringBuffer chars)
public boolean contentEquals(CharSequence chars)

Parameter Values

Parameter

Description

StringBuffer chars

The StringBuffer to search in.

CharSequence chars

The sequence of characters to search for.

 

The StringBuffer class, found in the java.lang package, functions similarly to a String but allows for modifications.

Additionally, the CharSequence interface, also located in the java.lang package, represents a readable sequence of char values

Technical Details

returns

A boolean indicating whether the exact sequence of characters exists in the specified string (or StringBuffer).

     

     True: The sequence of characters is present.
 False: The sequence of characters is absent.

Java Version

1.4 (contentEquals (StringBuffer chars))
1.5 (contentEquals (CharSequence chars))