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

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


public void whenCallRegionMatches_thenCorrect() {
    assertTrue("welcome to baeldung".regionMatches(false, 11, "baeldung", 0, 8));
Next »
Java String.replaceAll()
« Previous
Java String.regionMatches()
Java bottom

I just announced the new Learn Spring course, focused on the fundamentals of Spring 5 and Spring Boot 2:

Comments are closed on this article!