java tutorial - Java Strings regionMatches() method - java programming - learn java - java basics - java for beginners
Description
Java Strings regionMatches() method in Java has two options that can be used to test if the areas of the two strings are equal.
Syntax
Syntax method:
public boolean regionMatches(int toffset,
String other,
int ooffset,
int len)
or
public boolean regionMatches(boolean ignoreCase,
int toffset,
String other,
int ooffset,
int len)
click below button to copy the code. By - java tutorial - team
Options
Detailed information about the parameters:
- toffset - the initial offset of the subdomain in this line;
- other is a string argument;
- ooffset - initial offset of the subdomain in the string argument;
- len - the number of characters to compare;
- ignoreCase - true if case insensitive when comparing characters.
Return value
- In Java region, MapMatches () returns true if the specified subdomain of this string matches the sub-domain of the specified string argument; otherwise false.
Example 1
import java.io.*;
public class Test {
public static void main(String args[]) {
String Str1 = new String("Welcome to wikitechy.com");
String Str2 = new String("wikitechy");
String Str3 = new String("wikitechy");
System.out.print("Return Value :" );
System.out.println(Str1.regionMatches(11, Str2, 0, 9));
System.out.print("Return Value :" );
System.out.println(Str1.regionMatches(11, Str3, 0, 9));
}
}
click below button to copy the code. By - java tutorial - team
Output
Return Value :true
Return Value :true
Example 2
import java.io.*;
public class Test {
public static void main(String args[]) {
String Str1 = new String("Welcome to wikitechy.com");
String Str2 = new String("wikitechy");
System.out.print("Return Value :" );
System.out.println(Str1.regionMatches(true, 11, Str2, 0, 9));
}
}
click below button to copy the code. By - java tutorial - team
Output
Return Value :true