In Java, Character.toUpperCase(ch) returns the uppercase form of a character: 'a' becomes 'A', Greek small alpha becomes capital alpha. Characters without an uppercase form, such as digits and punctuation, come back unchanged.
It maps exactly one character to one character and never consults the locale. That is why German sharp s (U+00DF), whose uppercase is the two letters "SS", is returned unchanged; String.toUpperCase is the method that can expand it.
A static method of java.lang.Character (Java 1.0+): call it on the class, as in Character.toUpperCase(...); you do not need a Character object. No import is needed, because java.lang is always available. The int codePoint overload was added in Java 5.
Unicode version.
The answer comes from the Unicode Character Database built into your JDK, and each Java release follows a specific Unicode version (Java 8, for example, uses Unicode 6.2). The characters used on this page have had the same properties for many Unicode versions, so the examples print the same result on any current JDK.
Syntax
Pass a char to get a char, or an int code point to get an int.
Java
char a = Character.toUpperCase('a'); // 'A'
char b = Character.toUpperCase('A'); // 'A'
char c = Character.toUpperCase('\u00DF'); // '\u00DF', sharp s has no one-char uppercase
int d = Character.toUpperCase(0x03B1); // 0x0391 (913)
Overloads: char toUpperCase(char ch) and int toUpperCase(int codePoint). For capitalising the first letter of a word, toTitleCase() is the fully correct choice; for ordinary letters it gives the same result.
Library declarations
Java
// java.lang.Character
public static char toUpperCase(char ch)
public static int toUpperCase(int codePoint) // since Java 5
Parameters
Parameter
Description
ch (char)
The character to convert.
codePoint (int)
The code point to convert.
Return Value
Return Value
Description
char / int
The uppercase equivalent, or the argument itself if it has none.
Compare with Similar Methods
Related conversions:
Method
How it differs
String.toUpperCase(Locale)
Whole-string, locale-aware, can turn one character into two.
Example 1 — Capitalise the First Letter of Every Word
Uppercase each letter that follows a space, plus the very first one.
Java
public class CharacterToUpperCaseWords {
public static void main(String[] args) {
String text = "the quick brown fox";
StringBuilder out = new StringBuilder();
boolean startOfWord = true;
for (char c : text.toCharArray()) {
out.append(startOfWord ? Character.toUpperCase(c) : c);
startOfWord = (c == ' ');
}
System.out.println(out);
}
}
Output
The Quick Brown Fox
How It Works
A start-of-word flag.startOfWord is true for the first character and for every character right after a space.
Convert only word starts. The conditional expression picks the uppercase form for t, q, b, and f and leaves the other letters alone.
Both branches are chars.Character.toUpperCase(c) and c are both char, so append adds a letter; with an int branch, it would append a number.
Example 2 — Why Sharp s Stays Lowercase in Character.toUpperCase
Compare the single-character conversion with String.toUpperCase(Locale.ROOT) on the German word "Strasse" spelled with sharp s.
A Turkish locale object.Locale.forLanguageTag("tr") (Java 7+) builds the locale without the constructor that newer JDKs deprecate.
Always the same answer.Character.toUpperCase('i') returns 'I' (73) on every machine, because it ignores locales entirely.
Language rules in String. With the Turkish locale, String.toUpperCase returns U+0130 (304), LATIN CAPITAL LETTER I WITH DOT ABOVE; printing its code keeps the console output ASCII.
Frequently Asked Questions
Character.toUpperCase(s.charAt(0)) + s.substring(1), after checking that s is not empty. Use codePointAt and toChars if the first character may be above U+FFFF.
Its uppercase is the two letters SS, and the method can only return one character. String.toUpperCase can return SS.
No. It always uses the Unicode simple mapping. Use String.toUpperCase(Locale) for language-specific rules such as Turkish.
They differ only for a few digraph letters such as U+01C6: toUpperCase gives the all-capital form U+01C4, toTitleCase gives U+01C5.
No. Characters without case are returned unchanged.