Java Character valueOf() Method
Example
Create a Character object from a char:
public class Main {
public static void main(String[] args) {
char letter = 'A';
Character myChar = Character.valueOf(letter);
System.out.println(myChar);
}
}
Definition and Usage
The valueOf() method returns a Character object that holds a char value.
You need an object, not a primitive char, for example to store characters in an ArrayList<Character>. Java usually does this for you automatically, so Character myChar = 'A'; also works. This is called autoboxing.
Syntax
public static Character valueOf(char c)
Parameter Values
| Parameter | Description |
|---|---|
| c | Required. The character to store in the object. |
Technical Details
| Returns: | A Character object with the value of c. |
|---|
Related Pages
❮ Character Methods