集册 Java实例教程 更改字符串的大小写

更改字符串的大小写

欢马劈雪     最近更新时间:2020-01-02 10:19:05

465
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用toUpperCase()和toLowerCase()方法。

import java.util.Locale;

/* from 
NowJava.com - 时  代  Java*/

public class Main {

    public static void main(String[] args){


        String str = "This String will change case.";

        

        System.out.println(str.toUpperCase());

        System.out.println(str.toLowerCase());

        System.out.println(str.toUpperCase(Locale.ITALIAN));

        System.out.println(str.toUpperCase(new Locale("it","US")));

        System.out.println(str.toLowerCase(new Locale("fr", "CA")));

    }

    

 }