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

  • SEARCH
  • Home
  • 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 726617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:28:21+00:00 2026-05-14T06:28:21+00:00

I have three fields, namely Number1 Number2 Time I am trying to write a

  • 0

I have three fields, namely

  1. Number1
  2. Number2
  3. Time

I am trying to write a function in java that returns a unique hash value (long needs to be the return type of hash) for the above fields. This hash would then be used to store database rows corresponding to the above mentioned fields in a HashSet. I am new to writing a hash code function, can someone please review what I have.

public class HashCode {

    private long Number1;
    private long Number2;
    String Time;

    public HashCode(long Number1, long Number2, String Time){
        this.Number1 = Number1;
        this.Number2 = Number2;
        this.Time = Time;
    }

    public long getHashCode() {
        long hash = 3;
        hash = 47 * hash + (long) (this.Number1 ^ (this.Number1 >>> 32));
        hash = 47 * hash + (long) (this.Number2 ^ (this.Number2 >>> 32));
        hash = 47 * hash + (this.Time != null ? this.Time.hashCode() : 0);
        return hash;
    }
}
  • 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-14T06:28:21+00:00Added an answer on May 14, 2026 at 6:28 am

    I take it’s a special version of hashCode. Otherwise you would need to overwrite hashCode, don’t define a new method. Containers like HashSet don’t get your own hash code.

    • So for your specialized version for long, you do not need to use the xor (^) because it’s already long. Just use the long value.
    • When using hashCode of String it’s not for long, just for int, so it will not “use” all your space. You could duplicate the hashCode of String with longs for your purpose.
    • else looks good.

    (By the way, members should be called with lower letters and Time should be private as well.)

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

Sidebar

Related Questions

I have three fields that must be unique in a table, and based on
I have a list, that has three fields: Title, PublishingRollupImage and Description. I want
I have a program that uses three JTextField fields as the main data entry
I have created a datatable with three fields namely TimeTask, TaskItem and Count (count
I have these three fields in my jsp page. <td> <html:text property=my_dto.number1 </html:text> </td>
Hi Friend I Have a SqlDataBase in Which It Have Three Fields Namely **
I have a table with three fields, namely id (Primary Key), start_date (Date) and
What am I trying to do? I have three fields (1 hidden, an id)
I have three text fields: first name, last name, and age, also a photo.
I have a table with three fields, FirstName, LastName and Email. Here's some dummy

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.