Java String toUpperCase() method of String class is used to convert all characters of the string into an uppercase letter.
Example:
class Geeks
{
public static void main(String args[])
{
// Custom input string
String str = "Geeksforgeeks";
// Converting above input string to
// uppercase letters using UpperCase() method
String res = str.toUpperCase();
// Print the uppercased string
System.out.println(res);
}
}
Output
GEEKSFORGEEKS
Note: Lowercase is done using the rules of the given Locale.
There is 2 variant of toUpperCase() method. The key thing that is to be taken into consideration is toUpperCase() method worked the same as to UpperCase(Locale.getDefault()) method as internally default locale is used.
Java String toUpperCase(Locale locale)
The toUpperCase(Locale locale) method returns a new String object which is the original string in upper case with respect to the Locale method parameter.
Syntax String toUpperCase() Method in Java
public String toUpperCase(Locale loc)
Parameters:
- Type 1 : Locale value to be applied as it converts all the characters into
- Type 2 : NA
Example:
import java.util.Locale;
class Geeks
{
public static void main(String args[])
{
// Custom input string
String str = "Geeks for Geeks";
// Locales with the language "tr" for TURKISH
//"en" for ENGLISH is created
Locale TURKISH = Locale.forLanguageTag("tr");
Locale ENGLISH = Locale.forLanguageTag("en");
// Converting string str to uppercase letter
// using TURKISH and ENGLISH language
String strup1 = str.toUpperCase(TURKISH);
String strup2 = str.toUpperCase(ENGLISH);
System.out.println(strup1);
System.out.println(strup2);
}
}
Output
GEEKS FOR GEEKS GEEKS FOR GEEKS