Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Regarding String.equals and equals of Object Class

 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Could you please tell me the different between String.equals and the equals of Object Class, if both are same then
why we have equals method in String class we can use equals method of object class.


Thanks,
Santhosh Kumar V.K
 
Marshal
Posts: 22390
121
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because they're not the same.

Object.equals:
String.equals:
 
Sheriff
Posts: 4995
319
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have any idea yourself why this might be?

Hint: Equals is used for comparing instances of things. Think about what it means for two Object instances to be equal, and what it means for two String instances to be equal.
 
santhosh kumar vk
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for reply, both are checking the content are equals right then we will go for equals of object class instead of string.equals to check the string object
 
Tim Cooke
Sheriff
Posts: 4995
319
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

santhosh kumar vk wrote:then we will go for equals of object class instead of string.equals to check the string object


I don't understand what you mean by this? You don't get to choose.

But yes, Object has an .equals() method, as does String. The are different for good reason. Pretty much all you need to know about the == operator and .equals() method in relation to Strings can be found in this CodeRanch FAQ article
 
I got this tall by not having enough crisco in my diet as a kid. This ad looks like it had plenty of shortening:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic