❮ 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
| Parameter | Description |
|---|---|
| ignoreCase | Optional. When true the comparison between regions will be case-insensitive. Defaults to false. |
| offset | Required. The position in the string where the region starts. |
| other | Required. The string with the other region that is being compared. |
| otherOffset | Required. The position in the other string where the region starts. |
| length | Required. The size of the regions being compared. |
Technical Details
| Returns: | true if the two regions are equal, false otherwise. |
|---|---|
| Java version: | Any |