I have written the following program.
public class StringTest {
public static void main(String[] args){
String x = "\0";
String y = " ";
System.out.println("This is x - "+x+".");
System.out.println("This is y - "+y+".");
System.out.println(x.equals(y));
}
}
Of course, x.equals(y)
should clearly be false
, as they are completely different String
s. However, the output surprised me.
This is x - .
This is y - .
false
If these two String
s are NOT equal, then how could they produce the same output?