bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths

Loading lesson path

Learn/Java/Java Reference
Java•Java Reference

Java String regionMatches() Method

❮ String Methods

Example

String myStr1 = "Hello, World!";
String myStr2 = "New World";
System.out.println(myStr1.regionMatches(7, myStr2, 4, 5));
System.out.println(myStr1.regionMatches(0, myStr2, 0, 5));

Definition and Usage

The regionMatches() method compares regions in two different strings to check if they are equal.

One of the following

public boolean regionMatches(boolean
ignoreCase , int
offset , String
other , int
otherOffset , int
length )
public boolean regionMatches(int
offset , String
other , int
otherOffset , int
length )

Parameter Values

ParameterDescription
ignoreCaseOptional. When true the comparison between regions will be case-insensitive. Defaults to false.
offsetRequired. The position in the string where the region starts.
otherRequired. The string with the other region that is being compared.
otherOffsetRequired. The position in the other string where the region starts.
lengthRequired. The size of the regions being compared.

Technical Details

Returns:true if the two regions are equal, false otherwise.
Java version:Any

Previous

Java String offsetByCodePoints() Method

Next

Java String replace() Method