• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to override equals() method in java??

 
gopal kishan
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

how to override equals() method in java?? is it possible??

and can you tell me what is hashCode() where it works, and how??


thanks in advance
Gopal
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All you need to know about hashcode and equals, but were afraid to ask
 
Hentay Duke
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to override equals() method in java?? is it possible??


Yes it is possible

and can you tell me what is hashCode() where it works, and how??


Better for you to google for it and try it out yourself.
 
Jagan Nambi
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you can override equals().

In Java, java.lang.Object is at the top of the class hierarchy. The equals() method is declared in java.lang.Object as public boolean equals(Object obj). In your class, declare this method and write your code within this method. That basically constitutes overriding the equals() method.

Hope this helps!
 
gopal kishan
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI All,

Thanks for your reply.


regards
Gopal
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic