Touppercase Java

Hey guys!! Welcome to flower brackets blog. How are you doing. Today we are going to learn touppercase java.

toUpperCase java

Touppercase java

Not something you do everyday. But occasionally when you are manipulating input from a user you will need to do that.

Also Read – Learn Strings In Java

Well, converting input string to uppercase is very straightforward. In java we have two inbuilt methods and they are,

public String toUpperCase()

touppercase method converts all of the characters to uppercase using the rules of the default locale.

Let’s see java toUpperCase() 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. Case mapping is based on the Unicode Standard version specified by the Character class.

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