This week's book giveaway is in the Agile forum.
We're giving away four copies of Head First Agile and have Andrew Stellman & Jennifer Greene on-line!
See this thread for details.
Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

String s = "Hello"  RSS feed

 
jibs parap
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the bit pattern of 's' when its written:
String s = "Hello".

Thanks.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forget bit patterns. Read this TipLine Article: Strings Literally
 
jibs parap
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you are not correct. Read the article.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!