• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Which class override equals()?

 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
K&B book only mentioned String and Wrapper classes override equals() method. How about the Collection classes? I think all the concrete Collection class override equals() method as well. Am I correct?
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why not check the API documentation for the Collection classes you are interested in?
 
Ranch Hand
Posts: 1934
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my experience StringBuffer is the one which does not override equals and hashcode methods. All the general usage classes including Collections do over-ride these methods.
 
Jon Lee
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I already checked java docs, all classes in Collection override equals() method.

Thank you guys for your reply
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Kishore Dandu:
In my experience StringBuffer is the one which does not override equals and hashcode methods.



Well there's a method to this madness. Since StringBuffer
objects are mutable, how would you propose to improve on
the implementation of hashCode() inherited from Object?

StringBuffer sb = new StringBuffer("bar");
Hashtable ht = new Hashtable();
ht.put(sb, Boolean.TRUE);
sb.reverse(); // now contains "rab"
boolean found = ht.containsKey(sb);

Is it ok with you if found==false here?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic