String toUpperCase() method in java

Today we are going to learn string toUpperCase() method in java.

toUpperCase() method converts all of the characters of string to uppercase. Well, converting input string to uppercase is very straightforward.

Also read – learn strings in java

In java we have two inbuilt 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 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

Related Posts