How to represent an empty char in Java
Codemia Knowledge Hub ·
Java has no empty char: every primitive char holds exactly one 16-bit UTF-16 code unit. The usual stand-in is the null character '\u0000', which is also the default value of an uninitialized char and equal to Character.MIN_VALUE. If you need a real "no value", use the Character wrapper and set it to null.
Background: char and Character
The Character class in java.lang wraps a primitive char in an object and provides static methods for inspecting characters. A char itself occupies 16 bits and can never be "nothing", which is why text-processing and parsing code needs a convention for "no character here".
Options for an empty character
The null character '\u0000'
This is the default value of an uninitialized char. It is not truly empty, but it signals that no explicit character was set.
Character.MIN_VALUE
Character.MIN_VALUE is the smallest char value and is the same as '\u0000'. It can read more clearly than the escape sequence.
null with the Character wrapper
A Character is an object, so unlike a primitive char it can be null. This is the closest thing to a genuinely absent value.
A whitespace character
If you only need something invisible in output, a space ' ' or another whitespace character such as the non-breaking space '\u00A0' works. This is a display choice, not a marker for "no value".
Checking for the empty marker
Here, user input is simulated as the null character and checked before use:
Useful Character methods for this kind of check:
Character.isWhitespace(char): checks whether the character is whitespace.Character.isLetter(char): checks whether the character is a letter.Character.valueOf(char): converts a primitivecharto aCharacterinstance.
Quick reference
| Concept | Representation | Description |
| Null character | '\u0000' | Default uninitialized char, not truly empty, but signifies "no value". |
| Whitespace | ' ' or other Unicode spaces | Used for representing invisible characters visually. |
| Character minimum value | Character.MIN_VALUE | Equivalent to '\u0000', signifies the smallest value in char. |
| Null character object | null | When using Character objects, null signifies the absence of a character. |
Which one to pick depends on your logic: '\u0000' for a primitive placeholder, null when absence must be explicit, and whitespace only when the goal is visual.
Related reading
- How to resolve java.lang.NoClassDefFoundError, javax/xml/bind/JAXBException
- How to resolve module reads package error in java9
- How to resolve Unneccessary Stubbing exception
- How to respond with an HTTP 400 error in a Spring MVC @ResponseBody method returning String
- How to return 2 values from a Java method?
- How to return a custom object from a Spring Data JPA GROUP BY query
- How to return a custom response pojo when request body fails validations that are defined using Bean Validation/Hibernate Validator?
- How to return an HTML page from a RESTful controller in Spring Boot?
System design interview problems on this topic
- Design an API Rate Limiter: solution and walkthrough
- Design a Distributed Messaging System: solution and walkthrough
- Design an Online Payment Service: solution and walkthrough
- Design a Key Value Store: solution and walkthrough

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.