java 指定した文字列が含まれているかを判定する

java 指定した文字列が含まれているかを判定する

javaで、指定した文字列が含まれているかを判定する手順を記述してます。「contains」に文字列を指定することで可能です。

環境

  • OS windows11 home
  • java 19.0.1

手順

指定した文字列が含まれているかを判定するには、「contains」で可能です。

対象の文字列.contains( "文字列" )

※含まれていれば「true」,含まれていなければ「false」

実際に、使用してみます。

public class App {
    public static void main(String[] args) throws Exception {

        String str = "mebee";        
        
        System.out.println(str.contains("e")); // true       
        System.out.println(str.contains("eb")); // true
        System.out.println(str.contains("ea")); // false

    }
}

判定されていることが確認できます。