toUpperCase()方法toUpperCase()方法是String类方法,用于将给定的字符串转换为大写。
语法:
String String_object.toUpperCase();
在这里,String_object是一个String对象,我们必须将其转换为大写。该方法不更改字符串。它返回转换后的大写字符串。
示例
Input: str = "Welcome at NHOOO!" Function call: ans = str.toUpperCase() Output: ans = "WELCOME AT INCLUDEHELP!"
码:
public class Main
{
public static void main(String[] args) {
String str = "Welcome at NHOOO!";
String ans = str.toUpperCase();
System.out.println("str = " + str);
System.out.println("ans = " + ans);
}
}输出结果
str = Welcome at NHOOO! ans = WELCOME AT INCLUDEHELP!