「Java8」endsWith メソッドで文字列の末尾を比較する

環境
Eclipse 4.14
JavaSe 1.8

書式
public boolean endsWith(String suffix)
この文字列が、指定された接尾辞で終るかどうかを判定します。
パラメータ:suffix – 接尾辞。
戻り値:引数によって表される文字シーケンスが、
このオブジェクトによって表される文字シーケンスの接尾辞である場合はtrue、
そうでない場合はfalse。
endsWith メソッドを使用します。
一致する場合のみ、true を返します。
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
package com.arkgame.study;
public class ArkgamelDemo {
public static void main(String[] args) {
String str = "study";
System.out.println("末尾の文字列が一致");
boolean resultA = str.endsWith("udy");
System.out.println(resultA);
System.out.println("末尾の文字列が不一致");
boolean result2 = str.endsWith("st");
System.out.println(result2);
}
}
package com.arkgame.study; public class ArkgamelDemo { public static void main(String[] args) { String str = "study"; System.out.println("末尾の文字列が一致"); boolean resultA = str.endsWith("udy"); System.out.println(resultA); System.out.println("末尾の文字列が不一致"); boolean result2 = str.endsWith("st"); System.out.println(result2); } }
package com.arkgame.study;

public class ArkgamelDemo {

      public static void main(String[] args) {
            String str = "study";

            System.out.println("末尾の文字列が一致");
            boolean resultA = str.endsWith("udy");
            System.out.println(resultA);

            System.out.println("末尾の文字列が不一致");
            boolean result2 = str.endsWith("st");
            System.out.println(result2);

      }
}

結果
末尾の文字列が一致
true
末尾の文字列が不一致
false

Java

Posted by arkgame