Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String s = "Hello"

 
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic