您可以使用String类的 toUpperCase()方法将字符串中的单词大写。此方法将当前字符串的内容转换为大写字母。
public class StringToUpperCaseEmp {
public static void main(String[] args) {
String str = "string abc touppercase ";
String strUpper = str.toUpperCase();
System.out.println("Original String: " + str);
System.out.println("String changed to upper case: " + strUpper);
}
}输出结果
Original String: string abc touppercase String changed to upper case: STRING ABC TOUPPERCASE