温馨提示×

Java String类中的toUpperCase方法如何使用

小樊
82
2024-08-21 01:04:26
栏目: 编程语言

toUpperCase方法是用于将字符串中所有的字符转换为大写形式。以下是使用toUpperCase方法的示例:

String str = "hello world";
String upperCaseStr = str.toUpperCase();
System.out.println(upperCaseStr); // 输出: HELLO WORLD

在上面的示例中,我们首先创建一个字符串"hello world",然后调用toUpperCase方法将其转换为大写形式,并将结果存储在变量upperCaseStr中。最后,我们使用System.out.println方法打印出转换后的字符串。

0