The Java string toUpperCase() method of the String class has converted all characters of the string into an uppercase letter. There is two 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.
Syntax of toUpperCase Java
public String toUpperCase(Locale loc)
public String toUpperCase()
Parameters
- Type 1: Locale value to be applied as it converts all the characters into
- Type 2: NA
Return Type
- It returns the string in uppercase letters.
Note: Lowercase is done using the rules of the given Locale.
Example of toUpperCase Java
java
class GFG {
public static void main(String args[])
{
String str = "Welcome! to Geeksforgeeks";
String strup = str.toUpperCase();
System.out.println(strup);
}
}
|
OutputWELCOME! TO GEEKSFORGEEKS
Java String toUpperCase(Locale locale) Example
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.
Below is the Implementation of the above method:
java
import java.util.Locale;
class GFG {
public static void main(String args[])
{
String str = "Geeks for Geeks";
Locale TURKISH = Locale.forLanguageTag("tr");
Locale ENGLISH = Locale.forLanguageTag("en");
String strup1 = str.toUpperCase(TURKISH);
String strup2 = str.toUpperCase(ENGLISH);
System.out.println(strup1);
System.out.println(strup2);
}
}
|
OutputGEEKS FOR GEEKS
GEEKS FOR GEEKS