Java String.replace()

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

[source,java,gutter:,false]

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

Example

[source,java,gutter:,true]

@Test
public void whenCallRegionMatches_thenCorrect() {
    assertTrue("welcome to baeldung".regionMatches(false, 11, "baeldung", 0, 8));
}