Curriculum
Course: Java Basic
Login

Curriculum

Java Basic

Java Home

0/1

Java Introduction

0/1

Java Get Started

0/1

Java Syntax

0/1

Java Comments

0/1

Java Type Casting

0/1

Java Operators

0/1

Java Booleans

0/1

Java Switch

0/1

Java Break / Continue

0/1

Java Errors and Exception

0/1
Text lesson

regionMatches()

Example

Verify if two regions of strings are identical.

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 segments within two distinct strings to determine if they are identical.

Syntax

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. If set to true, the comparison between regions will be case-insensitive. Defaults to false

offset

Mandatory. The starting position in the string of the first region.

other

Mandatory. The string containing the second region being compared

otherOffset

Mandatory. The starting position in the second string of the second region.

length

Mandatory. The length of the regions being compared.

Technical Details

Returns

Returns true if the two regions are equal; otherwise, returns false.

Java Version

Any