Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

String constant pool

ziggy25Aug 21 2011 — edited Aug 22 2011
I thought that strings that are equal would always refer to the same object. The following code seem to suggest that is not the case
class ScjpTest{
	
	public static void main(String[] args){
	
		String a = "Hello";
		String b = "World";

		String c = a + "World";
		String d = "HellowWorld";

		String e = a.concat("World");

		System.out.println("d==c : " + d==c);
		System.out.println("d==e : " + d==e);
		
		
	}
}
output
false
false
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 19 2011
Added on Aug 21 2011
11 comments
358 views