logo

Metodo Java Character toUpperCase()

IL toUpperCase(char ch) Il metodo della classe Character converte l'argomento carattere specificato in maiuscolo utilizzando le informazioni di mappatura delle maiuscole fornite dal file Dati Unicode.

Va notato che Character.isUpperase(Character.UpperCase(ch)) potrebbe non restituire sempre true per alcuni caratteri.

In realtà, String.toUpperCase() può essere utilizzato per mappare i caratteri in maiuscolo. Esistono vari vantaggi della mappatura delle maiuscole e minuscole rispetto alla mappatura delle maiuscole e minuscole dei caratteri. La mappatura maiuscole e minuscole può essere utilizzata per eseguire mappature sensibili a livello locale, mappature sensibili al contesto mentre la mappatura maiuscole e minuscole dei caratteri non può essere utilizzata.

Sintassi

 public static char toUpperCase(char ch) 

Parametro

cap : È il carattere che deve essere convertito.

Valore di ritorno

Il metodo toUpperCase(char ch) restituisce la maiuscola del carattere specificato. Altrimenti, questo metodo restituisce il carattere stesso.

Esempio 1

 public class JavaCharacterToUpperCaseExample1 { public static void main(String[] args) { // Create four char primitives. char ch1, ch2, ch3, ch4; // Assign the values to ch1 and ch2. ch1 = 'm'; ch2 = 'q'; // Assign the uppercase of ch1 and ch2 to ch3 and ch4 respectively. ch3 = Character.toUpperCase(ch1); ch4 = Character.toUpperCase(ch2); String str1 = 'The uppercase of the character '' + ch1 + '' is given as: ' + ch3; String str2 = 'The uppercase of the character '' + ch2 + '' is given as: ' + ch4; // Print the values of ch1 and ch2. System.out.println( str1 ); System.out.println( str2 ); } } 
Provalo adesso

Produzione:

 The titlecase of character 'm' is given as: M The titlecase of character 'q' is given as: Q 

Esempio 2

 public class JavaCharacterToUpperCaseExample2{ public static void main(String[] args) { // Create four char primitives. char ch1, ch2, ch3, ch4; // Assign the values to ch1 and ch2. ch1 = '+'; ch2 = 'f'; // Assign the uppercase of ch1 and ch2 to ch3 and ch4 respectively. ch3 = Character.toUpperCase(ch1); ch4 = Character.toUpperCase(ch2); String str1 = 'The uppercase of the character '' + ch1 + '' is given as: ' + ch3; String str2 = 'The uppercase of the character '' + ch2 + '' is given as: ' + ch4; // Print the values of ch1 and ch2.. System.out.println( str1 ); System.out.println( str2 ); } } 
Provalo adesso

Produzione:

 The uppercase of the character '+' is given as: + The uppercase of the character 'F' is given as: F 


Metodo Java Character toUpperCase(int codePoint).

IL toUpperCase(int codePoint) Il metodo della classe Character converte l'argomento del carattere specificato (punto di codice Unicode) in maiuscolo utilizzando le informazioni di mappatura delle maiuscole fornite dal file di dati Unicode.

Va notato che Character.isUpperase(Character.UpperCase(codePoint)) potrebbe non restituire sempre true per alcuni caratteri.

In realtà, String.toUpperCase() può essere utilizzato per mappare i caratteri in maiuscolo. Esistono vari vantaggi della mappatura delle maiuscole e minuscole delle stringhe rispetto alla mappatura delle maiuscole e minuscole dei caratteri. La mappatura maiuscole e minuscole può essere utilizzata per eseguire mappature sensibili a livello locale, mappature sensibili al contesto mentre la mappatura maiuscole e minuscole dei caratteri non può essere utilizzata.

Sintassi

 public static int toUpperCase(int codePoint) 

Parametro

codePoint : È il codePoint il carattere che deve essere testato.

Valore di ritorno

Il metodo toUpperCase(int codePoint) restituisce la maiuscola del carattere specificato (punto di codice Unicode). Altrimenti, questo metodo restituisce il carattere stesso.

Esempio 1

 public class JavaCharactertoUpperCaseExample_1 { public static void main(String[] args) { // Initialize two char primitives. int codepoint1 = 102; int codepoint2 = 110; // Convert the codepoints to char type. char ch1 = (char) codepoint1; char ch2 = (char) codepoint2; // Convert the codepoints to uppercase. char upper1 = Character.toUpperCase(ch1); char upper2 = Character.toUpperCase(ch2); // Print the result. System.out.println('The uppercase for the character '' + ch1 + '' is given as: ' + upper1); System.out.println('The uppercase for the character '' + ch2 + '' is given as: ' + upper2); } } 
Provalo adesso

Produzione:

 The uppercase for the character 'f' is given as: F The uppercase for the character 'n' is given as: N 

Esempio 2

 public class JavaCharactertoUpperCaseExample_2 { public static void main(String[] args) { // Initialize two char primitives. int codepoint1 = 119; int codepoint2 = 80; // Convert the codepoints to char type. char ch1 = (char) codepoint1; char ch2 = (char) codepoint2; // Convert the codepoints to uppercase. char upper1 = Character.toUpperCase(ch1); char upper2 = Character.toUpperCase(ch2); // Print the result. String str1 = 'The uppercase for the character '' + ch1 + '' is given as: ' + upper1; String str2 = 'The uppercase for the character '' + ch2 + '' is given as: ' + upper2; System.out.println(str1); System.out.println(str2); } } 
Provalo adesso

Produzione:

 The uppercase for the character 'w' is given as: W The uppercase for the character 'P' is given as: P