posted 24 years ago
Hi,
The JVM Maintains a String Pool... for example...
1: String s1="Hello";
2: String s2="Hello";
3: String s3=new String("Hello");
In Line 1, the JVM creates a String "Hello" (LITERAL), and passes the reference to s1. In Line 2, the JVM sees that another string "Hello" has to be created, instead of creating one, it passes the reference of the previously created String to s2. FOR EFFICIENCY. That's why (s1==s2) is true.
The JVM maintains this pool.. consisting of strings created from only LITERALS. Hope you got the point. So you can see that (s2==s3) returns false.
ANYBODY: is this correct?
Bye
P.Nutan Prakash<br />SCJP2