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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:57:50+00:00 2026-06-12T18:57:50+00:00

Is it possible, in any language (it doesn’t matter), to have a hash function

  • 0

Is it possible, in any language (it doesn’t matter), to have a hash function which uses an array of strings as keys?

I mean something like this:

hash(["word1", "word2", ...]) = "element"

instead of the classical:

hash("word") = "element"

I need something like that because each word I would like to use as key could change the output element of the function. I’ve got a sequence of words and I want a specific output for that sequence (also the order may change the result).

  • 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-12T18:57:51+00:00Added an answer on June 12, 2026 at 6:57 pm

    Sure. Any data structure at all can be hashed. You only need to come up with a strict definition of equality and then ensure that hash(A) == hash(B) if A == B. Suppose your definition is that [s1, s2, …, sm] == [t1, t2, …, tn] if and only if m == n and si == ti for i = 1..m and further string s == t if and only if |s|==|t| and s[i]==t[i] for 0<=i<|s|. You can build a hash in a many, many ways:

    • Concatenate all the strings in the list and hash the result with any string hash function.
    • Do the same, adding separators such as commas (,)
    • Hash each string individually and xor the results.
    • Hash eash string individually, shift the previous hash value, and xor the new value into the hash.
    • Infinitely many more possibilities…

    Tigorous definition of equality is important. If for example order doesn’t matter in the lists or the string comparison is case-insensitive, then the hash function must still be designed to ensure hash(A) == hash(B) if A == B . Getting this wrong will cause lookups to fail.

    Java is one language that lets you define a hash function for any data type. And in fact a library list of strings will work just fine as a key using the default hash function.

    HashMap<ArrayList<String>, String> map = new HashMap<ArrayList<String>, String>();
    
    ArrayList<String> key = new ArrayList<String>();
    key.add("Hello");
    key.add("World");
    
    map.put(key, "It's me.");
    // map now contains mapping ["Hello", "World"] -> "It's me."
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible in Java (or any other language) to detect if there's an
Is it possible to learn C# as your first computer language without any knowledge
Is there any possible way to achieve this? For instance, I have an I/O
The Wikipedia article on Continuation says: In any language which supports closures , it
Is it possible, in C++ or any other compiled language, to add functionality to
Can any language be used to program in any paradigm? For example C doesn't
I have several strings in my site that don't belong to any app, for
Wikipedia mentions that In any language which supports closures and proper tail calls, it
Possible Duplicate: Any way to “reboot” the JVM? Is there any option to restart
Possible Duplicate: Any way to add HttpHandler programatically in .NET? Is there a way

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.