The method toUpperCase() converts all characters of a String to upper case. If no Locale is passed to the method, then it will use the default Locale.

However, it may produce unexpected results if it’s run on a system whose default Locale is different. To avoid this, we can simply pass the Locale to the method.

Available Signatures

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


public void whenConvertToUpperCase_thenCorrect() {
    String s = "Welcome to Baeldung!";
    assertEquals("WELCOME TO BAELDUNG!", s.toUpperCase());
Next »
Java String.trim()
« Previous
Java String.toLowerCase()
Course – LS – All

Get started with Spring and Spring Boot, through the Learn Spring course:

res – REST with Spring (eBook) (everywhere)
Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.