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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:38:05+00:00 2026-06-09T13:38:05+00:00

This is basically what I’m trying to do: enum Animal { CAT, FISH }

  • 0

This is basically what I’m trying to do:

enum Animal { CAT, FISH }
enum color { RED, GREEN }
int weight = 10
int IQ = 200
AnimalPrice.put((Animal.CAT, Color.GREEN, weight,IQ) , 5)

i.e. the price of a green cat that weights 10 pounds and has 200 iq is 5 dollars.
Is there a way to do this in java? I only got as far as using lists of integer as keys, but nothing about using enum types

  • 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-06-09T13:38:07+00:00Added an answer on June 9, 2026 at 1:38 pm

    There are 2 ways I would consider doing:

    1 create the keys as the string concatanation of those 4 values

    String key = Animal.CAT + '_' + Color.GREEN + '_' + weight + '_' + IQ;
    

    2 create an object made up of those values and create a custom equals and hashCode method

    public class AnimalPriceKey {
      private Animal animal;
      private Color color;
      private int weight;
      private int iq;
    
      public AnimalPriceKey(Animal animal, Color color, int weight, int iq) {
        this.animal = animal;
        this.color = color;
        this.weight = weight;
        this.iq = iq;
      }
    
      @Override
      public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((animal == null) ? 0 : animal.hashCode());
        result = prime * result + ((color == null) ? 0 : color.hashCode());
        result = prime * result + iq;
        result = prime * result + weight;
        return result;
      }
    
      @Override
      public boolean equals(Object obj) {
        if (this == obj)
          return true;
        if (obj == null)
          return false;
        if (getClass() != obj.getClass())
          return false;
        AnimalPriceKey other = (AnimalPriceKey) obj;
        if (animal != other.animal)
          return false;
        if (color != other.color)
          return false;
        if (iq != other.iq)
          return false;
        if (weight != other.weight)
          return false;
        return true;
      }
    }
    

    I would favor the second approach as it’s much more robust and future proof.

    Use example:

    Map<AnimalPriceKey, Integer> animalPrices = new HashMap<AnimalPriceKey, Integer>();
    animalPrices.put(new AnimalPriceKey(Animal.CAT, Color.GREEN, 10, 200), 5);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to to build a Felix bundle in Eclipse. This basically includes
Basically this is a question how to access local scope handler. I trying to
Im trying do this basically: var tr = document.createElement(tr); var td = document.createElement(td); td.appendChild(document.createTextNode('<input
I've tried a couple of ways to do this...Basically I'm trying to create a
In Android, I'm trying to accomplish this: Basically, the ability to add the button
This code basically translates characters based on position in one string to the character
This is basically a math problem, but very programing related: if I have 1
This is basically a duplicate of this question , but the accepted answer was
This is basically the same question as Click items in select box, and then
This is basically a 'best practices' question. Struts 1 forms have getters and setters

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.