Java String: toUppercase() Method
public String toUpperCase(Locale locale)
The toUppercase() method is used to convert all the characters in a given string to upper case using the rules of the given Locale. Case mapping is based on the Unicode Standard version specified by the Character class. Since case mappings are not always 1:1 char mappings, the resulting String may be a different length than the original String.
Examples of locale-sensitive and 1:M case mappings are in the following table.
Language Code of Locale | Lower Case | Upper Case | Description |
---|---|---|---|
tr (Turkish) | \u0069 | \u0130 | small letter i -> capital letter I with dot above |
tr (Turkish) | \u0131 | \u0049 | small letter dotless i -> capital letter I |
(all) | \u00df | \u0053\u0053 | small letter sharp s -> two letters: SS |
(all) | Fahrvergnügen | FAHRVERGNÜGEN |
Java Platform: Java SE 8
Syntax:
toUpperCase(Locale locale)
Parameters:
Name | Description | Type |
---|---|---|
locale | use the case transformation rules for this locale | String |
Return Value: the String, converted to uppercase.
Return Value Type: String
Pictorial presentation of Java String toUpperCase() Method
Example: Java String toUppercase(Locale locale) Method
The following example shows the usage of java String() method.
public class Example {
public static void main(String[] args)
{
String str = "The Quick BroWnFoX jumps over the laZy Dog!";
// Convert the above string to all lowercase.
String upper_str = str.toUpperCase();
System.out.println();
// Display the two strings for comparison.
System.out.println("Original String: " + str);
System.out.println("String in uppercase: " + upper_str);
System.out.println();
}
}
Output:
Original String: The Quick BroWnFoX jumps over the laZy Dog! String in uppercase: THE QUICK BROWNFOX JUMPS OVER THE LAZY DOG!
public String toUpperCase()
Converts all of the characters in this String to upper case using the rules of the default locale. This method is equivalent to toUpperCase(Locale.getDefault()).
Note: This method is locale sensitive, and may produce unexpected results if used for strings that are intended to be interpreted locale independently. Examples are programming language identifiers, protocol keys, and HTML tags. For instance, "title".toUpperCase() in a Turkish locale returns "T\u0130TLE", where '\u0130' is the LATIN CAPITAL LETTER I WITH DOT ABOVE character. To obtain correct results for locale insensitive strings, use toUpperCase(Locale.ROOT).
Syntax:
toUpperCase()
Return Value: the String, converted to uppercase.
Example: Java String toUppercase() Method
The following example shows the usage of java String() method.
public class StringUpperCaseExample {
public static void main(String[] args) {
// declaring our String object
String name = " John Gilbert ";
System.out.println();
// changing to lower case
String upperCaseName = name.toUpperCase();
System.out.println("Name in Upper Case: "+upperCaseName);
System.out.println();
}
}
Output:
Name in Upper Case: JOHN GILBERT
Java Code Editor:
Previous:toString Method
Next:trim Method
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/java-tutorial/string/string_touppercase.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics