Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Java String toUpperCase() Method With Examples

  • Difficulty Level : Basic
  • Last Updated : 04 Oct, 2021

The java string toUpperCase() method of String class has converted all characters of the string into an uppercase letter. There is two variant of toUpperCase() method. The key thing that is to be taken into consideration is toUpperCase() method worked same as to UpperCase(Locale.getDefault()) method as internally default locale is used. 

Syntax:

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

public String toUpperCase(Locale loc)
public String toUpperCase()

Parameter:  

  • Type 1: Locale value to be applied as it converts all the characters into
  • Type 2: NA

Return Type: It returns the string in uppercase letters.



Note: Lowercase is done using the rules of the given Locale.

Example 1:

java




// Java Program to Demonstrate Working of toUpperCase()
// method
  
// Main class
class GFG {
  
    // Main driver method
    public static void main(String args[])
    {
  
        // Custom input string
        String str = "Welcome! to Geeksforgeeks";
  
        // Converting above input string to
        // uppercase letters using UpperCase() method
        String strup = str.toUpperCase();
  
        // Print the uppercased string
        System.out.println(strup);
    }
}
Output
WELCOME! TO GEEKSFORGEEKS

Example 2:

java




// Java program to demonstrate Working of toUpperCase()
// method of Locale class
  
// Importing Locale class from java.util package
import java.util.Locale;
  
// Main class
class GFG {
  
    // Main driver method
    public static void main(String args[])
    {
  
        // Custom input string
        String str = "Geeks for Geeks";
  
        // Locales with the language "tr" for TURKISH
        //"en" for ENGLISH is created
        Locale TURKISH = Locale.forLanguageTag("tr");
        Locale ENGLISH = Locale.forLanguageTag("en");
  
        // Converting string str to uppercase letter
        // using TURKISH and ENGLISH language
        String strup1 = str.toUpperCase(TURKISH);
        String strup2 = str.toUpperCase(ENGLISH);
        System.out.println(strup1);
        System.out.println(strup2);
    }
}
Output
GEEKS FOR GEEKS
GEEKS FOR GEEKS



My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!