bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Java/Java Reference
Java•Java Reference

Java String equals() Method

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind Java String equals() 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.

___ myStr1 = "Hello";
3Order

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

The equals() method compares two strings, and returns true if the strings are equal, and false if not.
Definition and Usage
Java String equals() Method

❮ String Methods

Example

String myStr1 = "Hello";
String myStr2 = "Hello";
String myStr3 = "Another String";
System.out.println(myStr1.equals(myStr2)); // Returns true because they are equal
System.out.println(myStr1.equals(myStr3)); // false

Definition and Usage

The equals() method compares two strings, and returns true if the strings are equal, and false if not.

Tip

Use the compareTo() method to compare two strings lexicographically.

Syntax

public boolean equals(Object
anotherObject )

Parameter Values

ParameterDescription
anotherObjectAn Object , representing the other string to be compared

Technical Details

Returns:A boolean value: true - if the strings are equal false - if the strings are not equal
Overrides:equals in class Object
  • true - if the strings are equal
  • false - if the strings are not equal

Previous

Java String endsWith() Method

Next

Java String equalsIgnoreCase() Method