String toUpperCase() method in java

Let’s learn string toUpperCase() method in java.

String toUpperCase() method in java

String toUpperCase() method converts all characters in given string to uppercase using the rules of default locale.

Well, converting input string to uppercase is very straightforward.

Also read – variables in java

In java toUpperCase() method have two different methods. Here’s the syntax,

public String toUpperCase()

Let’s see an example,

public class StringToUppercaseDemo 
{
   public static void main(String[] args) 
   { 
      String strConvert = "flower brackets"; 
      String toUpper = strConvert.toUpperCase(); 
      System.out.println("To Uppercase - " + toUpper);
   }
}



Output:

string toUpperCase() method in java

Whereas touppercase(Locale loc) converts all the characters to uppercase using the rules of the given Locale.

public String toUpperCase(Locale loc)

Now let’s see java String toUpperCase(Locale loc) example,

import java.util.Locale;

public class ToUppercaseLocaleDemo 
{
   public static void main(String[] args) 
   {
      String str = "i love you java";
      Locale turkish = Locale.forLanguageTag("tr"); 
      Locale english = Locale.forLanguageTag("en");
      String str1 = str.toUpperCase(turkish); 
      String str2 = str.toUpperCase(english); 
      System.out.println(str1); 
      System.out.println(str2);
   }
}



Output:

? LOVE YOU JAVA
I LOVE YOU JAVA