Latest web development tutorials

JavaのregionMatches()メソッド

JavaのStringクラス JavaのStringクラス


二つの文字列内の領域を検出するためのregionMatches()メソッドは等しいです。

文法

public boolean regionMatches(int toffset,
                             String other,
                             int ooffset,
                             int len)

或

public boolean regionMatches(boolean ignoreCase,
                             int toffset,
                             String other,
                             int ooffset,
                             int len)

パラメータ

  • ignoreCase - trueの場合、比較文字は大文字小文字を無視します。

  • toffset -この文字列中性子領域開始オフセット。

  • 他の-文字列引数。

  • toffset -開始オフセット文字列パラメータの中性子領域。

  • LEN -比較する文字数。

戻り値

あなたが指定した場合、文字列のサブ領域は、文字列パラメータは、サブ領域を指定一致し、それはtrueを返し、そうでない場合はfalse。 正確に一致するか、場合を考えるには、ignoreCaseはパラメータに依存します。

public class Test {
	public static void main(String args[]) {
		String Str1 = new String("www.w3big.com");
		String Str2 = new String("w3big");
		String Str3 = new String("w3big");

		System.out.print("返回值 :" );
		System.out.println(Str1.regionMatches(4, Str2, 0, 5));

		System.out.print("返回值 :" );
		System.out.println(Str1.regionMatches(4, Str3, 0, 5));

		System.out.print("返回值 :" );
		System.out.println(Str1.regionMatches(true, 4, Str3, 0, 5));
	}
}

上記プログラムの実行結果:

返回值 :true
返回值 :false
返回值 :true

JavaのStringクラス JavaのStringクラス