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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:06:24+00:00 2026-05-26T08:06:24+00:00

How is this possible: HashMap<byte[], byte[]> and what is hash() of byte[]?

  • 0

How is this possible:
HashMap<byte[], byte[]> and what is hash() of byte[]?

  • 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-26T08:06:25+00:00Added an answer on May 26, 2026 at 8:06 am

    Yes, it is possible (with a big caveat, see below), but byte[] is not an “intrinsic type”. First, there’s no such thing, you probably mean a “primitive type”. Second: byte[] is not a primitive type, byte is. An array is always a reference type.

    Arrays don’t have specific hashCode implementations, so they’ll just use the hashCode of Object, which means that the hashCode will be the indentity-hashCode, which is independent from the actual content.

    In other words: a byte[] is a very bad Map key, because you can only retrieve the value with the exact same instance.

    If you need a content-based hashCode() based on an array, you can use Arrays.hashCode(), but that won’t help you (directly) with the Map. There’s also Arrays.equals() to check for content equality.

    You could wrap your byte[] in a thin wrapper object that implements hashCode() and equals() (using the methods mentioned above):

    import java.util.Arrays;
    
    public final class ArrayWrapper {
      private final byte[] data;
      private final int hash;
    
      public ArrayWrapper(final byte[] data) {
        // strictly speaking we should make a defensive copy here,
        // but I *assume* (and should document) that the argument
        // passed in here should not be changed
        this.data = data;
        this.hash = Arrays.hashCode(data);
      }
    
      @Override
      public int hashCode() {
        return hash
      }
    
      @Override
      public boolean equals(Object o) {
        if (!(o instanceof ArrayWrapper)) {
          return false;
        }
        ArrayWrapper other = (ArrayWrapper) o;
        return this.hash == other.hash && Arrays.equals(this.data, other.data);
      }
      // don't add getData to prevent having to do a defensive copy of data
    }
    

    Using this class you can then use a Map<ArrayWrapper,byte[]>.

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

Sidebar

Related Questions

Is this possible? I want to have the To:, Body, and an Attachment all
Is this possible? I am looking forward to a tutorial which explains the steps
Is this possible? I had troubles with SVN clients not being able to access
Is this possible? I can't find it anywhere.
Is this possible? Or would I miss something? (Fixtures,..?) Because: When I use autotest
Is this possible? I am creating a single base factory function to drive factories
Is this possible? I've followed the instructions from here ( http://www.jetbrains.net/confluence/display/TCD4/Setting+up+an+External+Database#SettingupanExternalDatabase-MicrosoftSQLServer2005 ) but I
Is this possible: myList = [] myList[12] = 'a' myList[22] = 'b' myList[32] =
Is this possible? example: $('a.change').click(function(){ //code to change p tag to h5 tag });
Is this possible? In an events system an event can have multiple times. (ie,

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.