Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Map inside Map in Scala

I've this code :

val total = ListMap[String,HashMap[Int,_]]
val hm1 = new HashMap[Int,String]
val hm2 = new HashMap[Int,Int]
...
//insert values in hm1 and in hm2
...
total += "key1" -> hm1
total += "key2" -> hm2

....

val get = HashMap[Int,String] = total.get("key1") match {
  case a : HashMap[Int,String] => a
}

This work, but I would know if exists a better (more readable) way to do this. Thanks to all !

like image 435
dacanalr Avatar asked Apr 17 '26 09:04

dacanalr


1 Answers

It looks like you're trying to re-implement tuples as maps.

val total : ( Map[Int,String], Map[Int,Int]) = ...

def get : Map[Int,String] = total._1
like image 105
Michael Lorton Avatar answered Apr 18 '26 22:04

Michael Lorton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!