Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

What is the Difference between equals() of Stringbuilder and String?

 
Shivom Shukla
Ranch Hand
Posts: 77
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Following is the code that confuses me..


Answer is true.
Why??
 
Winston Gutkowski
Bartender
Posts: 10777
71
Hibernate Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Shivom Shukla wrote:Why??


1. Look at the API for StringBuilder (←click).
2. Do you see an equals() method?
3. What happens in the absence of an equals() method?

HIH

Winston
 
Shivom Shukla
Ranch Hand
Posts: 77
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Winston,

Thanks a lot, your questions really solved my issue. I cannot believe I missed this.

Shivom
 
Winston Gutkowski
Bartender
Posts: 10777
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Shivom Shukla wrote:Thanks a lot, your questions really solved my issue. I cannot believe I missed this.


Don't worry. It still happens to me - although I suspect it's the Alzheimer's these days.

Winston
 
Ivan Jozsef Balazs
Rancher
Posts: 1041
6
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Strange. This line does not even compile for me:
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's because it's not valid Java. You can only use the shortcut {"1,2,4"} notation on a line where you declare as well as initialize a variable. You cannot use it for assignment to a variable that was declared earlier.

So it should be:

And ofcourse, you'll get a String array that has one element that contains "1,2,4" - not three elements "1", "2" and "4".
 
Shivom Shukla
Ranch Hand
Posts: 77
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My bad... That is absolutely correct what you have said.
Thanks for pointing it out.
 
Get off me! Here, read this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic