Java.lang.String.toUpperCase() 方法



描述

java.lang.String.toUpperCase(Locale locale) 方法使用給定區域設定的規則將此字串中的所有字元轉換為大寫。

宣告

以下是 java.lang.String.toUpperCase() 方法的宣告

public String toUpperCase()

引數

locale - 使用此區域設定的大小寫轉換規則。

返回值

此方法返回轉換為大寫的字串。

異常

示例

以下示例演示了 java.lang.String.toUpperCase() 方法的使用。

package com.tutorialspoint;

import java.lang.*;
import java.util.*;

public class StringDemo {

   public static void main(String[] args) {

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

讓我們編譯並執行上述程式,這將產生以下結果:

string value = THIS IS TUTORIALSPOINT
string value = WWW.TUTORIALSPOINT.COM
java_lang_string.htm
廣告