Java.lang.String.toUpperCase() 方法

描述

java.lang.String.toUpperCase() 方法使用默认语言环境的规则将此字符串中的所有字符转换为大写。


声明

以下是 java.lang.String.toUpperCase() 方法的声明。

public String toUpperCase()

参数

NA


返回值

此方法返回字符串,转换为大写。


异常

NA


示例

下面的例子展示了 java.lang.String.toUpperCase() 方法的使用。

package com.tutorialspoint;

import java.lang.*;

public class StringDemo {

   public static void main(String[] args) {

      // converts all lower case letters in to upper case letters
      String str1 = "This is TutorialsPoint";
      System.out.println("string value = " + str1.toUpperCase());
    
      str1 = "www.tutorialspoint.com";
      System.out.println("string value = " + str1.toUpperCase());
   }
}

让我们编译并运行上面的程序,这将产生下面的结果 −

string value = THIS IS TUTORIALSPOINT
string value = WWW.TUTORIALSPOINT.COM