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

  • Home
  • SEARCH
  • 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 6755271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:22:48+00:00 2026-05-26T13:22:48+00:00

If I have val key1 = mykey val key2 = 427 Is it possible

  • 0

If I have

val key1 = "mykey"
val key2 = 427

Is it possible to hash by both? I could do something like

val compoundKey = key1 + "#" + key2
myhash.put(compoundKey, value)

However that seems a bit clunky

  • 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-26T13:22:49+00:00Added an answer on May 26, 2026 at 1:22 pm

    I always prefer the new data type over Tuple for three reasons:

    case class CompoundKey(key1: String, key2: String)
    
    1. You have a name, especially in compiler warnings and an “expected CompoundKey” is clearer than a “expected Tuple2[String,String]“. Or it just helps you with a type annotation to make your own code more readable, especially in nested structures like Maps

      val k: CompoundKey = expensiveComputationOrNonObviousMethodCallsInARow(...)
      val keyMap: Map[CompoundKey,Key] instead of Map[(String,String),Key]

    2. Access to the subkeys in CompoundKey can be done by name:

      val ckey = CompoundKey("foo","bar")
      ckey.key1 instead of ckey._1

    3. It lets you change your representation of the nested type, here String, later on. That means if you change String to whatever that you doesn´t have to change Tuple2[String,String] all over your code. Only CompoundKey has to be adapted.

    (I even would use a wrapper case class Key(str: String) for the key class)

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

Sidebar

Related Questions

If you have something like: val myStuff = Array(Person(joe,40), Person(mary, 35)) How do you
I have val maxId = new ObjectId(...) and I want to query something like
Let's say I have some classes like this: abstract class View(val writer: XMLStreamWriter) {
I have a String: "{key1:value1}{key2:value2}" . I want to split these string using regular
At the moment I have val orders = new HashMap[Int, Int] orders.put(36, 110) orders.put(35,
So I have val list:List[Any]; def toElement(a:Any):scala.xml.Elem; And I want to write somthing like
I have a list of possible input Values val inputValues = List(1,2,3,4,5) I have
I have a DWORD value that in Hex might look like: DWORD Val =
I have string which contains something about amount 3 val 6, amount 7 val
You have: val array = new Array[Array[Cell]](height, width) How do you initialize all elements

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.