toUpperCase() Method in Java
Table of Content:
Description
The Character.toUpperCase(char ch) java method converts the character argument to uppercase using case mapping information from the UnicodeData file.
Note that Character.isUpperCase(Character.toUpperCase(ch)) does not always return true for some ranges of characters, particularly those that are symbols or ideographs.
In general, String.toUpperCase() should be used to map characters to uppercase. String case mapping methods have several benefits over Character case mapping methods. String case mapping methods can perform locale-sensitive mappings, context-sensitive mappings, and 1:M character mappings, whereas the Character case mapping methods cannot.
toUpperCase(char ch)
returns the uppercase form of the specified char value.
Method Syntax
public static char toTitleCase(char ch)
Method Argument
Data Type | Parameter | Description |
---|---|---|
char | ch | The character to be converted. Primitive character type. |
Method Returns
The toUpperCase(char ch) method of Character class returns the uppercase equivalent of the character, if any; otherwise, the character itself.
Compatibility
Requires Java 1.0 and up
Java Character toUpperCase(char ch) Example
Below is a simple java example on the usage of toUpperCase(char ch) method of Character class.
public class MethodtoUpperCase { public static void main(String args[]) { System.out.println(Character.toUpperCase('s')); System.out.println(Character.toUpperCase('S')); } }
output
Below is the sample output when you run the above example.
S S Press any key to continue . . .
Java Character toUpperCase(char ch) Example
Below is a simple java example on the usage of toUpperCase(char ch) method of Character class.
import java.util.Scanner; /* * This example source code demonstrates the use of * toUpperCase(char ch) method of Character class. */ public class CharacterToUpperCaseChar { public static void main(String[] args) { // Ask for user input System.out.print("Enter an input:"); // use scanner to get the user input Scanner s = new Scanner(System.in); // get a single character char[] value = s.nextLine().toCharArray(); // convert user input to upper case for(char ch:value){ char chUpper = Character.toUpperCase(ch); // print the result System.out.println("character "+ch +" Upper case is " +chUpper); } } }
output
Below is the sample output when you run the above example.
Enter an input:s character s Upper case is S Press any key to continue . . .