Java String regionMatches()
方法有兩個變體,可用於測試兩個字串區域是否相等。
語法
以下是此方法的語法 -
public boolean regionMatches(int toffset,
String other,
int offset,
int len)
參數
toffset
- 此字串中子區域的起始偏移量。other
- 字串參數。offset
- 字串參數中子區域的起始偏移量。len
- 要比較的字元數。
返回值
如果此字串的指定子區域與字串參數的指定子區域匹配,則返回true
;否則返回false
。匹配是精確匹配還是不區分大小寫取決於ignoreCase
參數。
示例
import java.io.*;
public class Test {
public static void main(String args[]) {
String Str1 = new String("Welcome to xuhuhu.com");
String Str2 = new String("zaixian");
String Str3 = new String("zaixian");
System.out.print("Return Value :" );
System.out.println(Str1.regionMatches(11, Str2, 0, 6));
System.out.print("Return Value :" );
System.out.println(Str1.regionMatches(11, Str3, 0, 6));
}
}
執行上面示例代碼,得到以下結果:
Return Value :true
Return Value :false
上一篇:
Java String類
下一篇:
Java快速入門