- Java.lang Package classes
- Java.lang - Home
- Java.lang - Boolean
- Java.lang - Byte
- Java.lang - Character
- Java.lang - Character.Subset
- Java.lang - Character.UnicodeBlock
- Java.lang - Class
- Java.lang - ClassLoader
- Java.lang - Compiler
- Java.lang - Double
- Java.lang - Enum
- Java.lang - Float
- Java.lang - InheritableThreadLocal
- Java.lang - Integer
- Java.lang - Long
- Java.lang - Math
- Java.lang - Number
- Java.lang - Object
- Java.lang - Package
- Java.lang - Process
- Java.lang - ProcessBuilder
- Java.lang - Runtime
- Java.lang - RuntimePermission
- Java.lang - SecurityManager
- Java.lang - Short
- Java.lang - StackTraceElement
- Java.lang - StrictMath
- Java.lang - String
- Java.lang - StringBuffer
- Java.lang - StringBuilder
- Java.lang - System
- Java.lang - Thread
- Java.lang - ThreadGroup
- Java.lang - ThreadLocal
- Java.lang - Throwable
- Java.lang - Void
- Java.lang Package extras
- Java.lang - Interfaces
- Java.lang - Errors
- Java.lang - Exceptions
- Java.lang Package Useful Resources
- Java.lang - Useful Resources
- Java.lang - Discussion
Java.lang.String.regionMatches() Method
Description
The java.lang.String.regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len) method tests if two string regions are equal.A substring of this String object is compared to a substring of the argument other.
The result is true if these substrings represent character sequences that are the same, ignoring case if and only if ignoreCase is true. The substring of this String object to be compared begins at index toffset and has length len. The substring of other to be compared begins at index ooffset and has length len.
Declaration
Following is the declaration for java.lang.String.regionMatches() method
public boolean regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len)
Parameters
ignoreCase − if true, ignore case when comparing characters.
toffset − the starting offset of the subregion in this string.
other − the string argument.
ooffset − the starting offset of the subregion in the string argument.
len − the number of characters to compare.
Return Value
This method returns true if the specified subregion of this string matches the specified subregion of the string argument, else false.
Exception
NA
Example
The following example shows the usage of java.lang.String.regionMatches() method.
package com.tutorialspoint; import java.lang.*; public class StringDemo { public static void main(String[] args) { String str1 = "Collection of tutorials"; String str2 = "Consists of different tutorials"; /* matches characters from index 14 in str1 to characters from index 22 in str2 considering same case of the letters */ boolean match1 = str1.regionMatches(14, str2, 22, 9); System.out.println("region matched = " + match1); /* considering different case, "true" is set which will ignore case when matched */ str2 = "Consists of different Tutorials"; match1 = str1.regionMatches(true, 14, str2, 22, 9); System.out.println("region matched = " + match1); } }
Let us compile and run the above program, this will produce the following result −
region matched = true region matched = true
To Continue Learning Please Login
Login with Google