Scala:获取Map.head元素的键(和值) [英] Scala: getting the key (and value) of a Map.head element

查看:264
本文介绍了Scala:获取Map.head元素的键(和值)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们想象一下下面的不变地图:

  val foo = Map((10,ten), one hundred))

我想获得第一个元素的键。



foo.head 获取第一个元素。

解决方案

设置键/值对:

val(key,value)= foo.head


Let's imagine the following immutable Map:

val foo = Map((10,"ten"), (100,"one hundred"))

I want to get the key of the first element.

foo.head gets the first element. But what next?

I also want the value of this element, i.e. "ten"

解决方案

Set a key/value pair:
val (key, value) = foo.head

这篇关于Scala:获取Map.head元素的键(和值)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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