Java toUpperCase() 示例
java 8object oriented programmingprogramming更新于 2025/12/9 23:40:17
UpperCase() 方法将所有字符转换为大写字母。此方法有两种变体。第一种变体使用给定 Locale 的规则将此字符串中的所有字符转换为大写。这相当于调用 toUpperCase(Locale.getDefault())。
示例
现在来看一个例子 −
import java.io.*;
public class Demo {
public static void main(String args[]) {
String Str = new String("This is it!");
System.out.print("Return Value :" );
System.out.println(Str.toUpperCase() );
}
}
输出
Return Value :THIS IS IT!
示例
让我们看另一个实现 toUpperCase() 方法的示例 −
import java.io.*;
import java.util.Locale;
public class Demo {
public static void main(String args[]) {
String str = new String("This is it!");
System.out.print("Return Value :" );
System.out.println(str.toUpperCase() );
Locale ENGLISH = Locale.forLanguageTag("en");
String res = str.toUpperCase(ENGLISH);
System.out.println(res);
}
}
输出
Return Value :THIS IS IT! THIS IS IT!

