Java toUpperCase() with examples


The UpperCase() method converts all characters to uppercase letters. This method has two variants. The first variant converts all of the characters in this String to upper case using the rules of the given Locale. This is equivalent to calling toUpperCase(Locale.getDefault()).

Example

Let us now see an example −

import java.io.*;
public class Demo {
   public static void main(String args[]) {
      String Str = new String("This is it!");
      System.out.print("Return Value :" );
      System.out.println(Str.toUpperCase() );
   }
}

Output

Return Value :THIS IS IT!

Example

Let us see another example to implement the toUpperCase() method −

import java.io.*;
import java.util.Locale;
public class Demo {
   public static void main(String args[]) {
      String str = new String("This is it!");
      System.out.print("Return Value :" );
      System.out.println(str.toUpperCase() );
      Locale ENGLISH = Locale.forLanguageTag("en");
      String res = str.toUpperCase(ENGLISH);
      System.out.println(res);
   }
}

Output

Return Value :THIS IS IT!
THIS IS IT!
raja
Published on 25-Sep-2019 08:48:39
Advertisements