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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:42:35+00:00 2026-05-21T05:42:35+00:00

I need a value of Someclass based on the key. And the key can

  • 0

I need a value of Someclass based on the key. And the key can be a string, boolean, or another Object, that’s why I used Object as key. But I have a problem, when the object is a string. and I have two Object of string, which is equals, but it should return different value, because it is a different object.

The code that I have:

Object k = new String("action");
Object l = new String("action");
Hashtable<Object,SomeClass> map = new Hashtable<Object, SomeClass>();

map.put(k,anObject1);
map.put(l,anObject2);

map.remove(k); // it is removing both with k and l.

when I check the hashCode() of both object, it returns the same value, which is ultimately what not I want.

Is there any solution of this? Is I need to make a new class that override Equals() of object? but, still, the hashCode. 🙁 The problem is I need a hashCode that return different value for different Object.

Edited:
I am doing this because I need to do different action based on what the string is, but the action will differ by the value returned by map with the key.

Updated:
Okay, here is all the story why I need this weird thing.

I have a player instance, and 3 land instances. So I wanted the player to plow land1, land2, land3. If the player wanted to plow a land, that land make a running thread, that tell the player to move to position X, and do the job action, and wait() by object action, and when the other thread notify this thread by object action, the land then modify itself. The player then make an animation based on the object action. I am having ArrayList<Position> destination and ‘ArrayList action` to have it. Maybe you can read my other question about this here.

So I wanted to make the action cancelable. I implements it by also passing the action object. I have a button that show for every action, and every button will cancel that action. I passing the action here too. So when I click the button, the land will get the notify. The problem is I can’t make the ArrayList<Position> remove the destination by the Action, because it’s don’t know where the index. I’m new to Java but have been using C++ a lot, so I thinking of using Hashtables, because it’s O(1) differs with C++ O(log n), and kind of convenience because not many changes to my current code.

Is it understandable?

  • 1 1 Answer
  • 1 View
  • 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-21T05:42:36+00:00Added an answer on May 21, 2026 at 5:42 am

    You could use an IdentityHashMap instead, though it might help if you could explain what exactly you’re trying to do here. This is not a terribly common requirement and unless you have some very good reasons you want to do this, there’s probably something else you’re better off doing.

    By the way, a Map can only hold one value for a single key. So after your second call to map.put, the first value you put in there is already gone.

    Edit:

    Ok, I’ve read your explanation and… well, I’m still not completely clear on what you’re doing. Here’s my best guess from what you’ve said:

    • You have an action called “plow”, represented as a String.
    • You are telling the player to “plow” 3 different lands.
    • You want to be able to cancel that action for one land without cancelling it for the others.
    • To do this, you’re trying to map 3 different instances of the String “plow” to the Positions of the 3 different lands.

    If this (or something like it) is what you’re trying to do, here are my thoughts:

    • The action String should not be unique… “plow” is “plow”, whatever land it is done on. What is unique is the combination of an action like “plow” and the land that action is to be done on.
    • Given that, “plow” should be considered something like an “action type”. It might be good to use an enum or some such to represent action types.
    • An Action class should contain an “action type” and a Position. When you click to cancel that Action, you have the data you need right there.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When creating a new entity object that has a foreign key value I need
i need Enumarable value from below class but give error public static Enumerable LoadDataByName(string
I have a boolean(primitive) variable in my bean. I need its value to be
MSDN docs say that only value types need boxing, but this does not apply
I'm designing a Java based web-app and I need a key-value store. Berkeley DB
I have an app where I need a BOOL value to persist across launches.
For example i have this xml. I need to get value of parameter val
we need to evaluate a value in an object in run time while we
I have some text that looks like: California(2342) My object has a property that
I have class SomeClass with properties. For example id and name : class SomeClass(object):

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.