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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:24:05+00:00 2026-06-03T11:24:05+00:00

Is it possible to create a HashMap whose key is an array of integers?

  • 0

Is it possible to create a HashMap whose key is an array of integers?

I´m accustomed to use Python and just recently I began working with Java. In my job I need to create a HashMap with keys like:

map.put([5,2], 1);
map.put([3,2], 0);

and so on. I´m using it to later on test if a pair of those numbers are present in the map, if yes, then do something, if not, continue.

To do so I tried the following:

Map<Array, Boolean> test = new HashMap<Array, Boolean>();
int[] a1 = {5,2};
test.put(a1, true);

Eclipse gives the message (“The arguments are not applicable to int[]…”). But any configuration I´ve done I get some error.

I tried using ArrayList, Objects inside the map, nested HashMap and so on but none worked (in python it´s very easy, I´d just write dict[(5,2)] = 1, so I imagine in Java there´s something simple like that). I was suggested to transform the numbers into Strings and add a colon between then, like:

map.put("5:2", 1);

and later on I break the string again but if this is the solution I´ll go back to Python ;)!!

Probably this is a very simple question but I couldn´t find the answer, hope you can help me.

Thanks in advance!

  • 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-03T11:24:11+00:00Added an answer on June 3, 2026 at 11:24 am

    If you want to check for the existance of your entry, you can use a Set (a useful concrete implementation is HashSet.

    final Set<List<Integer>> population;
    
    population = new HashSet<List<Integer>>();
    population.add(Arrays.asList(1, 2));
    
    if (population.contains(Arrays.asList(1, 2)))
    {
      ...
    }
    

    You can use an List as I have done above – but that doesn’t guarantee that all your lists are exactly two elements long (if that is indeed a constraint). To make it a bit more robust, you could create your own class to represent the tuple. If you do, make sure you implement equals() and hashCode() (here’s an article explaining good practice).

    Arrays.asList() is a useful way of creating a list in-line in the code. A more general list is an ArrayList.

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

Sidebar

Related Questions

Possible Duplicate: Cannot create an array of LinkedLists in Java…? I want to call
Possible Duplicate: Create Excel file in Java How to save output in excel format
Is it possible to create an environment to safely run arbitrary Python scripts under
Possible Duplicate: Create an Iframe from a Drupal Website I'd like to use an
Is it possible create a IPhone application by using java and LWUIT framework?
Hi it'd like to know if it's at all possible create a parametric equalizer
Possible Duplicate: Create shortcut to console.log() In javascript we can easy assign functions to
Possible Duplicate: create multiple variables based on an int count Objective C Equivalent of
Is it possible to create ASP.NET MVC applications in VS 2010? What should I
Is it possible to create invisible form fields in an NSIS installer? I'm using

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.