How to represent empty char in Java Character class

How to represent empty char in Java Character class

You may assign u0000 (or 0).
For this purpose, use Character.MIN_VALUE.

Character ch = Character.MIN_VALUE;

char means exactly one character. You cant assign zero characters to this type.

That means that there is no char value for which String.replace(char, char) would return a string with a diffrent length.

How to represent empty char in Java Character class

As Character is a class deriving from Object, you can assign null as instance:

Character myChar = null;

Problem solved 😉

Leave a Reply

Your email address will not be published.