Possible Duplicate:
How to represent empty char in Java Character class
I am using the replace function as defined in java.lang.String, and I tried using “\0” as the equivalent for “” (blank String) but it adds a space not a blank string.
Is there a Character equivalent for a blank String?
There is no such thing as an “empty character”. A
charis a value-type, so it has to have a value. An absence of a value is the absence of achar– which is why you can have empty strings (i.e. “no characters”) and a nullable char, but not an “empty char”.Anyway, the
String.replace(char, char)method is meant to substitute one character for another. This operation is very simple because it means that a single block of known size has to be allocated. WhereasString.replaceAll(string,string)is a considerably more complicated method to implement, which is why they’re different.Unfortunately there is no
String.replace(char,string)method – but I hope you can understand why.