在Scala中的Map内部地图 [英] Map inside Map in Scala

查看:50
本文介绍了在Scala中的Map内部地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此代码:

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 !

推荐答案

您似乎正在尝试将元组重新实现为地图.

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

这篇关于在Scala中的Map内部地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆