Java 实例 - 字符串小写转大写


以下实例使用了 String toUpperCase() 方法将字符串从小写转为大写:

  1. //StringToUpperCaseEmp.java 文件
  2.  
  3. public class StringToUpperCaseEmp {
  4. public static void main(String[] args) {
  5. String str = "string abc touppercase ";
  6. String strUpper = str.toUpperCase();
  7. System.out.println("Original String: " + str);
  8. System.out.println("String changed to upper case: "
  9. + strUpper);
  10. }
  11. }
  12.  

以上代码实例输出结果为:

  1. Original String: string abc touppercase
  2. String changed to upper case: STRING ABC TOUPPERCASE