In Java, Character.valueOf(c) returns a Character object holding the charc. This is called boxing, and it is what the compiler uses when you write Character boxed = 'x'; (autoboxing, Java 5+).
valueOf keeps a cache: it always returns the same object for chars from \u0000 to \u007F (the ASCII range). Other values may or may not be cached, so compare Character objects with equals, not ==.
A static method of java.lang.Character (Java 5+): call it on the class, as in Character.valueOf(...); you do not need a Character object. No import is needed, because java.lang is always available.
Syntax
Pass a primitive char.
Java
Character a = Character.valueOf('k'); // explicit boxing
Character b = 'k'; // autoboxing: calls valueOf('k')
a == b // true, 'k' is in the cache
a.equals(b) // true, always the right way
Call
What it does
Character.valueOf(c)
Box a char.
list.add(c)
Autoboxing calls valueOf for you.
a.equals(b)
Compare boxed values safely.
One overload, valueOf(char c), since Java 5. It is preferred over the Character(char) constructor, which is deprecated since Java 9.
Library declarations
Java
// java.lang.Character (since Java 5)
public static Character valueOf(char c)
Parameters
Parameter
Description
c (char)
The char to wrap.
Return Value
Return Value
Description
Character
An object holding c; the shared cached object when c is \u0000 to \u007F.