[java] How to represent empty char in Java Character class

You can only re-use an existing character. e.g. \0 If you put this in a String, you will have a String with one character in it.


Say you want a char such that when you do

String s = 
char ch = ?
String s2 = s + ch; // there is not char which does this.
assert s.equals(s2);

what you have to do instead is

String s = 
char ch = MY_NULL_CHAR;
String s2 = ch == MY_NULL_CHAR ? s : s + ch;
assert s.equals(s2);