This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

String Buffer  RSS feed

 
Arun Kumarr
Ranch Hand
Posts: 662
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String str ="Java";
StringBuffer one = new StringBuffer(str);
StringBuffer two = new StringBuffer(str);

Now "one.equals(two)" prints false.

I believe, StringBuffer doesn't override the equals method to compare the values of the string??

Am I correct??
 
Hentay Duke
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A quick look into the API reveals that indeed StringBuffer does not override the equals method it inherits from Object.


"Do not fear the API"
 
Georgy Bolyuba
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Arun Kumarr:

I believe, StringBuffer doesn't override the equals method to compare the values of the string??


Nether equals() nor hashCode();
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!