Java String toUpperCase()

The syntax of the string toUpperCase() method is:

string.toUpperCase()

toUpperCase() Parameters

  • doesn't take any parameters

toUpperCase() Return Value

  • returns a string with all lower case letters converted to upper case

Example: Java toUpperCase()

class Main {
  public static void main(String[] args) {
    String str1 = "Learn Java";
    String str2 = "Java123";

    // convert to upper case letters
    System.out.println(str1.toUpperCase()); // "LEARN JAVA"
    System.out.println(str2.toUpperCase()); // "JAVA123"
  }
}

As you can see from the above example, toUpperCase() converts all lower case letters to upper case letters.


toUpperCase() With Locale Parameter

The toUpperCase() method can also take a locale as an argument. This allows you to convert all characters in a string to upper case using the given Locale (such as: Turkish, Lithuanian etc.) rules.

Its syntax is:

string.toUpperCase(Locale locale)

If you do not pass the locale parameter, the default locale, Locale.getDefault(), is used.

To learn more, visit Java toUpperCase() With Locale.


To convert all characters in a string to lower case letters, use the Java String toLowerCase() method.

Did you find this article helpful?

Your builder path starts here. Builders don't just know how to code, they create solutions that matter.

Escape tutorial hell and ship real projects.

Try Programiz PRO
  • Real-World Projects
  • On-Demand Learning
  • AI Mentor
  • Builder Community