String toUpperCase() method in java

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

String toUpperCase() method in java

String toUpperCase method have two variants.

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

String toUpperCase() method converts a string to uppercase letters.

Here’s String toUpperCase() method example or java program to convert string into uppercase.

public class StringToUppercaseDemo
{
   public static void main(String[] args)
   {
      String str = "flower brackets";
      System.out.println(str.toUpperCase());
   }
}


Output:

FLOWER BRACKETS


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

public String toUpperCase(Locale locale)

Now let’s see java String toUpperCase(Locale loc) method 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


Also read – Binary search in java