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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:19:13+00:00 2026-05-26T03:19:13+00:00

Assume we have three sets of strings in Scala. One has elements A,B,C. Two

  • 0

Assume we have three sets of strings in Scala. One has elements A,B,C. Two has elements B,C,D. And Three has elements J,K,I.

My first question is, is there any way that the hashcodes for any two of these sets could be the same?
My second question is, if I add D to One and A to Two to get new Sets One.n and Two.n, are the hashcodes for One.n and Two.n the same?

  • 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-26T03:19:14+00:00Added an answer on May 26, 2026 at 3:19 am

    Question 1) In general yes, entirely possible. A hashcode is a limited number of bytes long. A Set can be any size. So hashcodes cannot be unique (although usually they are).

    Question 2) Why not try it?

    scala> val One = collection.mutable.Set[String]("A", "B", "C")
    One: scala.collection.mutable.Set[String] = Set(A, B, C)
    
    scala> One.hashCode
    res3: Int = 1491157345
    
    scala> val Two = collection.mutable.Set[String]("B", "C", "D")
    Two: scala.collection.mutable.Set[String] = Set(B, D, C)
    
    scala> Two.hashCode
    res4: Int = -967442916
    
    scala> One += "D"
    res5: One.type = Set(A, B, D, C)
    
    scala> Two += "A"
    res6: Two.type = Set(B, D, A, C)
    
    scala> One.hashCode
    res7: Int = -232075924
    
    scala> Two.hashCode
    res8: Int = -232075924
    

    So, yes they are, as you might expect, since you would expect the == method to be true for these two instances.

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

Sidebar

Related Questions

What have I marked as --assume-unchanged ? Is there any way to find out
Let's assume I have a model called product. Let's assume that product has three
Assume I have created a compiled re: x = re.compile('^\d+$') Is there a way
Assume I have 10 Methods and 10 Properties. Is there a way to add
Firstly, let me set out what I'd like to do. Assume I have three
How do I have a script run every, say 30 minutes? I assume there
Do graphic cards have instruction sets of their own? I assume they do, but
This is a more theoretical question, not a specific scenario: Let's assume, we have
In my app, users have one template record (in Template table) that sets defaults
Assume we have three arrays of length N which contain arbitrary numbers of type

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.