The below code printed different output in different system.
String s = "hello?vsrd".replace('?', '\0');
System.out.println(s);
When I tried in my system (Linux Ubuntu, Netbeans 7.1), it printed :
When I tried the same code in another system (Linux Mint, Netbeans 7.1) it printed as
I do understand that \0
acts as a character in java (by referring this answer and obviously s.length() prints 10). And, non-printable characters may be printed like this (box). But, why this behaves only on some systems? is it the difference of jdk version or OSs? I don't want an alternative code, but want to know why exactly it happens so.
You can just consider String s = "hello\0vsrd";
.