Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3670626
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:23:18+00:00 2026-05-19T02:23:18+00:00

I have a basic class ‘HistoryItem’ like so: public class HistoryItem private Date startDate;

  • 0

I have a basic class ‘HistoryItem’ like so:

public class HistoryItem
  private Date startDate;
  private Date endDate;
  private Info info;
  private String details;

  @Override
  public int hashCode() {
    int hash = (startDate == null ? 0 : startDate.hashCode());
    hash = hash * 31 + (endDate == null ? 0 : endDate.hashCode());
    return hash;
  }
}

I am currently using a HashSet to remove duplicates from an ArrayList on the startDate & endDate fields, which is working correctly.

However I also need to remove duplicates on different fields (info & details).

My question is this.
Is there a way to specify a different method which HashSet will use in place of hashCode()?
Something like this:

public int hashCode_2() {
  int hash = (info == null ? 0 : info.hashCode());
  hash = hash * 31 + (details == null ? 0 : details.hashCode());
  return hash;
}

Set<HistoryItem> removeDups = new HashSet<HistoryItem>();
removeDups.setHashMethod(hashCode_2);

Or is there another way that I should be doing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T02:23:19+00:00Added an answer on May 19, 2026 at 2:23 am

    I ended up using GNU Trove for this.

    Minimal code change was required.

    A new class implementing TObjectHashingStrategy (containing HashCode and Equals methods).

    public class HistoryItemDuplicateInfo
    implements TObjectHashingStrategy<HistoryItem> {
    
      @Override
      public int computeHashCode(HistoryItem obj) {
         ...
      }
    
      @Override
      public boolean equals(HistoryItem arg0, HistoryItem arg1) {
        ...
      }
    }
    

    Then use the THashSet object with a specified strategy for removing the duplicates.

    THashSet<HistoryItem> hs = new THashSet<HistoryItem>(new HistoryItemDuplicateInfo());
    

    Hope this is able to help someone out in future.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a basic ruby class: class LogEntry end and what i would like
I have very basic class: class Customer { protected $id; protected $customer; public function
Let say I have a basic 2D vector class something like class vector2 {
What are containers/adapters? I have basic knowledge of C++ and its sub-topics like (class/templates/STL).
I have a basic CRUD form that uses PageMethods to update the user details,
I have a basic quiz/survey type application I'm working on, and I'd like to
I have a basic class that derived subclasses inherit from, it carries the basic
Let's say I have a basic class A that aggregate B and C: class
I have a basic model: class Person(models.Model): first_name = models.CharField(max_length=50) last_name = models.CharField(max_length=50) state
I have a very basic class that is a list of sub-classes, plus some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.