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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:03:00+00:00 2026-05-20T11:03:00+00:00

I have a lookup table that should be accessed by two separate key values.

  • 0

I have a lookup table that should be accessed by two separate key values. One ugly way to do this is:

int[][] myArray = new int[256][256];
myArray[key1][key2] = 25;

where key1 and key2 are keys that were previously generated dynamically. But this is rather ugly. It seems that a better way to do this would be to use a Map, but those require a single key, not two. Java doesn’t natively support tuples, so what should I use instead? (It also seems awkward to use an array as the key).

EDIT: The reason I say that this isn’t particularly pretty is that my array is actually referenced by character values, not integers. They could be used interchangeably, but the responses to my previous question seem to suggest otherwise:

2D Array in Java, Indexed by Characters

  • 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-20T11:03:01+00:00Added an answer on May 20, 2026 at 11:03 am

    What’s so ugly about that? That’s about as simple as 2D matrices can be in Java, and it’s quick, too.

    If you really want to use a map, just defined your own Tuple class to use as a key – but be sure that you override equals() and hashCode() correctly! I’d recommend implementing an immutable Tuple class because using mutable objects as map keys can cause serious issues.

    Tuple.java

    package q5128376;
    
    import java.util.Arrays;
    
    public class Tuple<T>
    {
        private T[] values;
        private int hashCode;
    
        private Tuple(T... values)
        {
            this.values = values;
            this.hashCode = hashCode(values);
        }
    
        public static <T> Tuple<T> create(T... values)
        {
            return new Tuple<T>(values);
        }
    
        private static <T> int hashCode(T... values)
        {
            return 31 * Arrays.hashCode(values);
        }
    
        @Override
        public int hashCode()
        {
            return hashCode;
        }
    
        @Override
        public boolean equals(Object obj) 
        {
            if (this == obj) return true;
            if (!(obj instanceof Tuple<?>)) return false;
            Tuple<?> other = (Tuple<?>) obj;
            if (!Arrays.equals(values, other.values)) return false;
            return true;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm compiling a lookup table that needs to have 133,784,560 entries, with values ranging
I have two database tables. One table stores data for a commitment that a
I have a DataGridViewComboBoxColumn in a DataGridView that's based on a lookup table. The
I have a script that appends some rows to a table. One of the
I have created a lookup table in Access to provide the possible values for
I have a case where I need to translate (lookup) several values from the
I have a mysql database table that will store locations for buildings and events
I have a lookup table in Excel with ColA and ColB : ColA ColB
If I have a lookup table with very few records in it (say, less
We currently have a Lookup table which contains a set of possible choices for

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.