This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes String s = Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "String s = "Hello"" Watch "String s = "Hello"" New topic
Author

String s = "Hello"

jibs parap
Ranch Hand

Joined: Dec 07, 2004
Posts: 134
What is the bit pattern of 's' when its written:
String s = "Hello".

Thanks.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Forget bit patterns. Read this TipLine Article: Strings Literally


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
jibs parap
Ranch Hand

Joined: Dec 07, 2004
Posts: 134
I wanted to know why the output is true for s1==s2 if:
s1="Hello"
s2="Hello"

System.out.println(s1==s2)

//== looks into the bit patterns of variable; as String literal variable s1 and s2 have the same bit pattern which reads Hello. And thats why s1==s2 is true.

Is my argument right?
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
No, you are not correct. Read the article.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String s = "Hello"