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 6828173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:21:07+00:00 2026-05-26T22:21:07+00:00

Given an object we will call loc that simply holds 2 int member values,

  • 0

Given an object we will call loc that simply holds 2 int member values, I believe I need to come up with a mechanism to generate a hashcode for the object. What I tried below doesn’t work as it uses an object reference, and the 2 references will be different despite having the same members variables.

Map<Loc,String> mapTest = new HashMap<Loc,String>();
        mapTest.put(new Loc(1,2), "String 1");
        mapTest.put(new Loc(0,1), "String 2");
        mapTest.put(new Loc(2,2), "String 3");

        System.out.println("Should be String 2 " + mapTest.get(new Loc(0,1)));

After some reading it seems I need to roll my own hashcode for this object, and use that hashcode as the key. Just wanted to confirm that I am on the right track here, and if someone could guide me to simple implementations to look at that would be excellent.

Thanks

  • 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-26T22:21:07+00:00Added an answer on May 26, 2026 at 10:21 pm

    Yes, you’re on the right track.

    See articles like this for more details.

    There are a lot of different ways to implement a hashcode, you’ll probably just want to combine the hashcodes of each integer primitive.

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

Sidebar

Related Questions

Given any object I can call #public_methods and see all the methods it will
Do you generally assume that toString() on any given object has a low cost
I have an object pool, and I need to call a delegate method OnFree(),
I'm trying to write a method that will return a Hibernate object based on
How can I create an Object in ruby that will be evaluated to false
I need to call a virtual method for all classes derived from a given
Given: Object innerProxy = ... Object proxy = java.lang.reflect.Proxy. newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[]{type}, innerProxy); How
How do I check if a given object is nullable in other words how
How do I list available methods on a given object or package in Perl?
I am writing common functions to serialize the given object and List<object> as follows

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.