java 文字列を小文字に変換する

java 文字列を小文字に変換する

javaで、文字列を小文字に変換する手順を記述してます。「toLowerCase」で可能です。全角も変換することができます。

環境

  • OS windows11 home
  • java 19.0.1

手順

文字列を小文字に変換するには、「toLowerCase」を使用することで可能です。

文字列.toLowerCase()

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

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

        String str1 = "MEBEE";
        String str2 = "mEEBE";
        
        System.out.println(str1.toLowerCase()); // mebee 
        System.out.println(str2.toLowerCase()); // mebee

    }
}

変換されていることが確認できます。

全角も小文字に変換されます。

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

        String str1 = "M";
        
        System.out.println(str1.toLowerCase()); // m 

    }
}

大文字に変換

逆に大文字に変換する場合は「toUpperCase」を使用します。

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

        String str1 = "mebee";
        String str2 = "Mebee";
        
        System.out.println(str1.toUpperCase()); // MEBEE 
        System.out.println(str2.toUpperCase()); // MEBEE

    }
}