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

環境
Windows11 pro 64bit
java 17.0.2

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

使用例

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("ee"));
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("ee")); 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("ee")); 
        System.out.println(str.endsWith("me")); 
        System.out.println(str.endsWith("E"));

  }
}

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
true
false
true
false
true false true false
true
false
true
false

 

Java

Posted by arkgame