String toUpperCase() method java

Hey guys!! Welcome to flower brackets blog. How are you doing? Today we are going to learn string toUpperCase() method java.

String toUpperCase() method java

This 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 ToUppercaseDemo 
{
   public static void main(String[] args) 
   { 
      String strConvert = "flower brackets"; 
      String toUpper = strConvert.toUpperCase(); 
      System.out.println("To Uppercase - " + toUpper);
   }
}

Output:

To Uppercase – FLOWER BRACKETS


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