java endsWith指定した文字列が後方に含まれているかを判定するサンプル

環境
Windows11 Pro 64bit
java 19.0.1

構文
対象の文字列.endsWith( “文字列" )
指定した文字列が後方に含まれているかを判定するには、「endsWith」を使います
含まれていれば「true」,含まれていなければ「false」

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
public class Main {
public static void main(String[] args) throws Exception {
String str = "arkgame";
System.out.println(str.endsWith("e"));
System.out.println(str.endsWith("gam"));
System.out.println(str.endsWith("me"));
System.out.println(str.endsWith("E"));
}
}
public class Main { public static void main(String[] args) throws Exception { String str = "arkgame"; System.out.println(str.endsWith("e")); System.out.println(str.endsWith("gam")); System.out.println(str.endsWith("me")); System.out.println(str.endsWith("E")); } }
public class Main {
    public static void main(String[] args) throws Exception {

        String str = "arkgame";        
        
        System.out.println(str.endsWith("e"));     
        System.out.println(str.endsWith("gam"));
        System.out.println(str.endsWith("me"));
        System.out.println(str.endsWith("E")); 

    }
}

実行結果
true
false
true
false

 

IT

Posted by arkgame