The method regionMatches() checks if two String regions are equal.

Here are a few important points:

  • ignoreCase specifies whether we should ignore the case of both Strings
  • toffset determines the starting index of the first String
  • other specifies the second String.
  • ooffset specifies the starting index of the second String
  • len specifies the number of characters to compare

Available Signatures

boolean regionMatches(int toffset, String other, int ooffset, int len)
boolean regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len)

Example

@Test
public void whenCallRegionMatches_thenCorrect() {
    assertTrue("welcome to baeldung".regionMatches(false, 11, "baeldung", 0, 8));
}
Next »
Java String.replace()
« Previous
Java String.lastIndexOf()
Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – Black Friday 2026 – NPI EA – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW