Java Tutorial Java Advanced Java References

Java String - toUpperCase() Method



The Java toUpperCase() method returns the string with all characters of the specified string in uppercase, using the rules of the default locale or specified locale.

Syntax

public String toUpperCase()
public String toUpperCase(Locale locale)

Parameters

locale specify locale to use the case transformation rules.

Return Value

Returns the uppercased version of the specified string.

Example:

In the example below, toUpperCase() method is used to convert all characters of the given string in the uppercase, using default locale.

public class MyClass {
  public static void main(String[] args) {
    String MyString = "HeLLo John!";
    String NewString = MyString.toUpperCase();

    System.out.println(NewString);
  }
}

The output of the above code will be:

HELLO JOHN!

Example:

In the example below, French locale is used to convert all characters of the given string in the uppercase.

import java.util.Locale;

public class MyClass {
  public static void main(String[] args) {
    String MyString = "HeLLo John!";
    Locale locale = new Locale("fr", "FR");

    String NewString = MyString.toUpperCase(locale);

    System.out.println(NewString);
  }
}

The output of the above code will be:

HELLO JOHN!

❮ Java String Methods