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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:13:07+00:00 2026-06-04T19:13:07+00:00

I want to create a map that has two key : map.put (key1,key2,value1);// Insert

  • 0

I want to create a map that has two key :

map.put (key1,key2,value1);// Insert into map
map.get(key1,key2); // return value1

i have looking into multikeyMap but i don’t know how i will do it

  • 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-04T19:13:09+00:00Added an answer on June 4, 2026 at 7:13 pm

    Sounds like you just want a key which is created from two values. You may well find that those two values should naturally be encapsulated into another type anyway – or you could create a Key2<K1, K2> type. (The naming here would allow for Key3, Key4 etc. I wouldn’t encourage you to go too far though.)

    For something in between, you could create a private static class within the class where this is really needed (if it’s only an internal implementation detail). If it’s not a natural encapsulation (e.g. it’s something like “name and population”, which doesn’t make sense outside this specific scenario) then it would be good in terms of keeping meaningful property names, but without exposing it publicly.

    In any of these scenarios, you’ll end up with a new type with two final variables which are initialized in the constructor, and which contribute to both equals and hashCode. For example:

    public final class Key2<K1, K2> {
        private final K1 part1;
        private final K2 part2;
    
        public Key2(K1 part1, K2 part2) {
            this.part1 = part1;
            this.part2 = part2;
        }
    
        @Override public boolean equals(Object other) {
            if (!(other instanceof Key2)) {
                return false;
            }
            // Can't find out the type arguments, unfortunately
            Key2 rawOther = (Key2) other;
            // TODO: Handle nullity
            return part1.equals(rawOther.part1) &&
                part2.equals(rawOther.part2);
        }
    
        @Override public int hashCode() {
            // TODO: Handle nullity
            int hash = 23;
            hash = hash * 31 + part1.hashCode();
            hash = hash * 31 + part2.hashCode();
            return hash;
        }
    
        // TODO: Consider overriding toString and providing accessors.
    }
    

    The more situation-specific types would be slightly simpler as they wouldn’t be generic – in particular this would mean you wouldn’t need to worry about the type arguments, and you could give the variables better names.

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

Sidebar

Related Questions

I want to create a map which has a certain class as a key.
I want to create a Map object that can lose value only if we
I want to create an Android application that has a MapView at the top
We want to use MapKit / MKOverlayView to create a map that looks totally
I want to create a territories map on Google Maps that follows zip code
I want to create application which would display spatial data on Map. I'm thinking
I am using oozie to run my map-reduce job. I want to create the
I want create a excel with Apache POI in java and I must insert
I want to create a stored procedure (on SQL Server 2005) that fetches a
Have a Map which contains objects that I want to keep in sync across

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.