Java .contentEquals()

christian.dinh's avatar
Published Jul 26, 2021Updated Sep 3, 2021
Contribute to Docs

Returns true if the sequence of characters in the string is equal to the content of the specified string. If not, returns false.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.
    • Beginner Friendly.
      17 hours

Syntax

string.contentEquals(CharSequence characters)
  • characters (required): A character value specifies the sequence of characters to be searched for.

Example 1

Call the .contentEquals() method on the word string with the arguments "water" and "watermelon":

class isContentEqual {
public static void main(String[] args) {
String word = "watermelon";
System.out.println(word.contentEquals("water"));
System.out.println(word.contentEquals("watermelon"));
// Output: false
// Output: true
}
}

All contributors

Contribute to Docs

Learn Java on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.
    • Beginner Friendly.
      17 hours