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)


public void whenCallRegionMatches_thenCorrect() {
    assertTrue("welcome to baeldung".regionMatches(false, 11, "baeldung", 0, 8));
Next »
Java String.replace()
« Previous
Java String.lastIndexOf()
Course – LS – All

Get started with Spring and Spring Boot, through the Learn Spring course:

res – REST with Spring (eBook) (everywhere)
Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.