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

equals hashcode

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have created a Class

I am using this object in Arraylist and sorting the list based on this. Then i am adding the list of this objects(List<ClassA> to HashSet, Then i am populating another List<ClassA> if it is not there in hashset.


The question here is should i have to implement equals and hashcode methods in ClassA. If so caan anyone give an efficient equal and hashcode impl code.

Thanks in advance
 
author & internet detective
Posts: 41775
887
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Manoj,
The first step is to define what you want object equality to mean. (just id or all fields, what level of granularity for the date)

Note that nobody here will write your code for you. We will help you so do feel free to post your first attempt here for comments/direction.
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This code means you want to sort A class's objects array....

No you don't need to implement either of these methods because you are comparing on basis of date and date already has these methods.
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Manoj lal please UseAMeaningfulSubjectLine
"equals hashcode" makes little or no sense at all.

Also please take some time to read the ask good questions link below.


Hope this helps
 
Replace the word "snake" with "danger noodle" in all tiny ads.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic