Java toUpperCase() with examples

The java string toUpperCase() method converts all characters of the string into a uppercase letter. There are two variant of toUpperCase() method.
Signature:

public String toUpperCase(Locale loc) 
and
public String toUpperCase() 
Parameter:
loc- locale value to be applied.It converts all the characters into 
lowercase using the rules of given Locale.  
Returns: returns string in uppercase letter.
filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate
// working of toUpperCase() method
  
class Gfg {
    public static void main(String args[])
    {
        String str = "Welcome! to Geeksforgeeks Planet.";
  
        // converting string str to uppercase letter
        String gfg1 = str.toUpperCase();
        System.out.println(gfg1);
    }
}

chevron_right


Output:

WELCOME! TO GEEKSFORGEEKS PLANET.
filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate
// working of Locale class in
// toUpperCase() method
import java.util.Locale;
class Gfg {
    public static void main(String args[])
    {
        String str = "i Know YOi BuI You Don't Know ME.";
  
        // 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 gfg2 = str.toUpperCase(TURKISH);
        String gfg3 = str.toUpperCase(ENGLISH);
        System.out.println(gfg2);
        System.out.println(gfg3);
    }
}

chevron_right


Output:

? KNOW YO? BUI YOU DON'T KNOW ME.
I KNOW YOI BUI YOU DON'T KNOW ME.


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



Improved By : mihir89